【问题标题】:leaderboard example not run when change folder structure更改文件夹结构时不运行排行榜示例
【发布时间】:2013-12-11 18:50:46
【问题描述】:

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

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

我现在尝试了解meteor.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 中的 leaderboard.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.

【问题讨论】:

    标签: javascript meteor


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 您还必须复制类似于Players = new Meteor.Collection('players') 的顶行,您会在leadership.js 中注意到它不在isServerisClient 块中,因为它在两者上共享
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    • 1970-01-01
    • 2012-04-24
    • 2017-08-04
    • 2013-06-03
    • 2013-02-26
    • 1970-01-01
    相关资源
    最近更新 更多