2017-03-04 36 views
0

說我有一個Meteor.user()對象,看起來像這樣:尋找從Meteor.user()用戶名用戶名和它匹配不同的集合

{_id: "xxxxxxxx", username: "john"} 

和我有不同的集合,被稱爲profiles,即看起來是這樣的:

{_id: "yyyyyyy", username: "john", firstname: "John", lastname: "Doe", etc...} 

很顯然,我能夠從Meteor.user().username設置profilesusername財產。

然而,當我嘗試匹配客戶端上的這一信息:

import Profile form '../imports/api/profiles' 

Template.AddInfo.helpers({ 
    interests(){ 
    return Profile.find({username: Meteor.user().username}); 
    } 
}); 

,並在我的玉模板有這樣的代碼:

each interests 
    p #{username} 

什麼也不顯示。

注:我也試過findOne({...})以及相同的結果。

我在這裏做錯了什麼?在客戶端上處理Meteor.user()的方式有問題嗎?

在此先感謝。

+0

你是怎麼訂閱'Profile'集合的? – sonlexqt

回答

0

您似乎沒有訂閱發佈Profile數據的出版物。假設您沒有使用autopublish,那麼您必須在服務器上定義發佈功能。

Meteor.publish("profiles", function() { 
    return Profile.find({}); 
}); 

然後從您的onCreated回調模板中訂閱此模板。

Template.AddInfo.onCreated(function() { 
    this.subscribe('profiles'); 
}); 
+0

哦,哦,你說得對。忘記了我已經從我的包文件中刪除了'autopublish'。謝謝! – brownac

相關問題