当我在服务器上定义我的流星集合并尝试在客户端访问它们而不是在任何流星提供的方法中时,rendered, events, created, helpers ...
我总是收到一个错误,Meteor collection not defined
如果我尝试在客户端中重新定义方法,我会得到Meteor collection already exists
. 我可以通过在Meteor.startup()
函数中引用我的定制集合来解决这个问题。我如何引用我在客户端的服务器上定义的集合。在流星文档中Meteor.Collection()
,甚至可以在声明之前创建两个实例并进行订阅。
// okay to subscribe (and possibly receive data) before declaring
// the client collection that will hold it. assume "allplayers"
// publishes data from **server's "players" collection.**
Meteor.subscribe("allplayers");
...
// client queues incoming players records until ...
...
Players = new Meteor.Collection("players");