2015-06-14 73 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的显微镜项目)测试了它,它对我很有用。希望它也适用于你。如果不是,请在这里留言,并且如果它有效,一定要接受这个答案。 =)