2013-10-24 58 views
7

我知道這個問題已被問了很多次,但我很難發佈這些信息。發佈自定義Meteor.user()字段

在Accounts.onCreateUser我增加了現場,像這樣

{ 
... 
user['info'] = { email: options.email, is_admin: false}; 
} 

我發佈這個信息;

Meteor.publish('user', function() { 
    return Meteor.users.find({}, { fields: { info: 1} }); 
} 

Meteor.subscribe('user'); 

調試後發佈查詢返回正確的信息,但是當我試圖訪問Meteor.user是從來沒有給客戶端()。我必須做其他事情才能讓信息被Meteor.user()訪問嗎?

有什麼建議嗎?

回答

18

您將希望使用null發佈到單個用戶。

Meteor.publish(null, function() { 
    return Meteor.users.find({_id: this.userId}, {fields: {info: 1}}); 
}); 
+2

請原諒我的流星newbyness,但你能解釋或提供使用null作爲發佈名稱的任何文檔或教程參考嗎?訂閱是否需要或現在的值是否會在當前用戶對象中自動顯示?謝謝! – shawnim

+1

無需訂閱 - 發佈null意味着'autopublish'(不要與名爲autopublish的Meteor包混淆)。 http://support.kadira.io/knowledgebase/articles/379961-what-is-null-autopublish-publication –