-3

在这个Meteor 应用程序中,我有一个 Meteor 集合和一些subscribe调用,这些调用应该用服务器发布的至少一条记录来填充它。此外,还有铁路由器wait()调用它。但是,该集合永远不会被填充。服务器确实发送了记录,因为客户端预先订阅的另一个集合接收了它。

问题也在 GitHub 上,以防它被证明是一个错误。

4

1 回答 1

1

I think there might be 2 problems.

The first is that the published data ends up in the collection, Books, on the client. That is the collection it is in on the server and that is the collection it will end up in on the client if the publish returns a cursor. Have a close look at the counts-by-room example in the docs and see how publish subscribe names match but that collection names need to be set with custom 'added(), remove(), changed() blocks to manage a collection of a different name on the client than the server.

The second problem is in how you are checking for the data on the client. Iron-router waits for the subscribe handle's ready() to return true. But that true just means that the server has sent all the data. From the docs on ready()- "True if the server has marked the subscription as ready. A reactive data source."

So the server has sent all the data but it might not yet be on the client. So you always need to check that the data you want is there and never assume that all the data has arrived just because the subscription is ready().

Try adding this to your client code:

Deps.autorun( function(){
   // replace this.params.name with the name because it is no longer in scope
   console.log( Books.findOne( {name: this.params.name} )); 

});

And I think it will log the data you are looking for soon after the subscribe is ready.

于 2014-02-18T10:14:51.960 回答