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