【发布时间】:2015-11-06 23:00:08
【问题描述】:
我有这个简单的代码,基本上是尝试从头开始重新创建 Players 示例。我用一行创建了一个项目
meteor create simpl
并拥有此代码
Players = new Meteor.Collection("players");
if (Meteor.isClient) {
Meteor.startup(function () {
console.log(Players.find().count());
});
if (Meteor.isServer) {
Meteor.startup(function () {
if (Players.find().count() === 0) {
Players.insert({name:"meteor"});
Players.insert({name:"meteor1"});
}
});
}
控制台输出 0。Leaderboard 示例中插入和检索的相等代码按预期工作,但不是这个。我在项目的代码或创建中做错了吗?
更新:
在阅读了一些关于在服务器上发布和在客户端订阅的要求的 cmets 和答案后,我想问一下 Leaderboard 示例为什么没有这样的代码,但可以工作正如我所料。
【问题讨论】:
-
查看文档(docs.meteor.com/#structuringyourapp),它出现在创建您需要在服务器上发布它们然后在客户端上订阅的集合之后。
标签: meteor