更改文件夹结构时未运行排行榜示例

leaderboard example not run when change folder structure

本文关键字:运行 排行榜 文件夹 结构      更新时间:2024-06-28

这次我学习了metro.js:D我从榜样中学习。我现在使用的例子是排行榜:http://www.meteor.com/examples/leaderboard从本机示例项目中,我有这样的文件夹结构:

leaderboard
|-.meteor
|-leaderboard.css
|-leaderboard.html
|-leaderboard.js

我现在试着理解metro.js文件夹的结构,我试着移动到这样:

leaderboard
|-.meteor
|-client
    |--leaderboard.css
    |-leaderboard.html
    |-leaderboard.js
|-public
|-server

我没有更改任何代码,只是创建文件夹并移动然后我启动流星并访问localhost:3000但网络不起作用。帮助我如何解决这个问题,请告诉我如何使用私人文件夹:D

感谢

更新我尽量听从指示。我与领导一起更新我的服务器文件夹。

Meteor.startup(function () {
    if (Players.find().count() === 0) {
      var names = ["Ada Lovelace",
                   "Grace Hopper",
                   "Marie Curie",
                   "Carl Friedrich Gauss",
                   "Nikola Tesla",
                   "Claude Shannon"];
      for (var i = 0; i < names.length; i++)
        Players.insert({name: names[i], score: Math.floor(Random.fraction()*10)*5});
    }
  });

我在/client中的排行榜.js也更新了,没有if(Meteor.isClient)这是我的错误:

Your app is crashing. Here's the latest log.
W2036-17:49:01.658(7)? (STDERR) D:'Meteor'leaderboard'.meteor'local'build'programs'server'boot.js:195
W2036-17:49:01.661(7)? (STDERR) }).run();
W2036-17:49:01.662(7)? (STDERR)    ^
W2036-17:49:01.663(7)? (STDERR) ReferenceError: Players is not defined
W2036-17:49:01.665(7)? (STDERR)     at app/server/leadership.js:2:9
W2036-17:49:01.666(7)? (STDERR)     at D:'Meteor'leaderboard'.meteor'local'build'programs'server'boot.js:168:61
W2036-17:49:01.668(7)? (STDERR)     at Array.forEach (native)
W2036-17:49:01.669(7)? (STDERR)     at Function._.each._.forEach (C:'Users'yoza'AppData'Local'.meteor'tools'e42f0b78d3'lib'node_modules'underscore'underscore.js:79:11)
W2036-17:49:01.671(7)? (STDERR)     at D:'Meteor'leaderboard'.meteor'local'build'programs'server'boot.js:168:5
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.

leadership.js中有代码也需要放在.js文件中的/server文件夹中。

if(Meteor.isClient){中的所有代码都只能在客户端上运行。所以应该放在/client文件夹中。当它位于客户端文件夹中时,不需要if(Meteor.isClient){条件检查。

同样地,if(Meteor.isServer) {中的内容属于/server文件夹。

它不起作用,因为/client中的文件只在客户端运行,而且还有一些服务器端部分,如集合,需要在服务器上运行。