2015-06-14 42 views
0

我想在我的模板中顯示所有用戶的列表。 我有:流星:發佈所有用戶不工作,沒有自動發佈包

//publications.js 
Meteor.publish('users', function() { 
    return Meteor.users.find({}, { fields: {username: 1, profile: 1} }); 
}); 

//router.js 
Router.route('/users/add/:_id?', {name: 'users.add', controller: 'UserAddController'}); 

UserAddController = RouteController.extend({ 
    subscriptions: function(){ 
    return [ Meteor.subscribe('hospitals'), 
      Meteor.subscribe('roles'), 
      Meteor.subscribe('users') ]; 
    }, 
    action: function() { 
    this.render('addUser', { 
     data: function(){ 
     return { hospital_id : this.params._id } 
     } 
    }); 
    } 
}); 


//client 
Template.listUsers.helpers({ 
    users: function() { 
    return Meteor.users.find({}); 
    } 
}); 

但該列表只顯示當前登錄的用戶。我創建了一個使用Account.createUser()函數的用戶列表我做錯了什麼?

謝謝。

+0

您的publications.js文件位於何處?它應該在服務器目錄中。 –

+0

是的,它在服務器目錄中。 –

+0

檢查您的模板。還要在瀏覽器控制檯中執行'Meteor.users.find()。fetch()',看它是否包含所有用戶。 –

回答

0

你必須使用this.subscribe()來訂閱出版物中subscriptions鉤:

// a place to put your subscriptions 
subscriptions: function() { 
    this.subscribe('items'); 

    // add the subscription to the waitlist 
    this.subscribe('item', this.params._id).wait(); 
} 

或者使用waitOn:

// Subscriptions or other things we want to "wait" on. This also 
// automatically uses the loading hook. That's the only difference between 
// this option and the subscriptions option above. 
waitOn: function() { 
    return Meteor.subscribe('post', this.params._id); 
} 
0

默認情況下,流星發佈當前用戶。我看到你有一個addUser模板和一個listUsers模板。問題是,雖然addUser訂閱users發佈,listUsers不(這將取決於你還有什麼你的路由器當然)。要解決此問題,請將呼叫更改爲this.render以呈現listUsers模板。然後,你的幫手應該工作,並且你可以渲染你喜歡的信息。

我用我自己的應用程序(DiscoverMeteor的顯微鏡項目)測試了它,它對我很有用。希望它也適用於你。如果不是,請在這裏留言,並且如果它有效,一定要接受這個答案。 =)