1
在我的用户采集渲染数组列表,我有叫synonym_ids
的数组。一个储存在一个Collection流星
什么是显示这个客户端上的最简单的方法?
我试图从发布服务器下面,然后从客户端订阅。不过,我得到这个错误:
Internal exception while starting subscription 0ea473b6-8be4-43ec-8a56-988409a4b58a Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.
#server
Meteor.publish 'synonym_ids',() ->
if Meteor.userId()
return Meteor.users.findOne({_id: Meteor.userId()}).synonym_ids
#client
Meteor.autosubscribe() ->
Meteor.subscribe 'synonym_ids'
您是否尝试过repla通过this.UserId ceMeteor.userId()? – 2013-03-13 01:46:06
@Oscar,那么我将如何将其表现为模板? – Gezim 2013-03-13 02:06:11
@Oscar是对的:将'if Meteor.userId()'改为'if this.userId'。我想你可能还需要从publsh函数返回一个光标或者做更高级的事情。尝试'返回Meteor.users.find({_ id:this.userId},{fields:{synonym_ids:1}})'以确保用户看到该字段。然后在客户端上,一旦订阅完成,您应该可以使用'Meteor.user()。synonym_ids'来访问'synonym_ids'。 – zorlak 2013-03-13 06:35:10