Meteor的相关项目
我有团队和项目,项目与特定组相关。 在一个组的“详细信息页面”上,我想查看属于特定组的所有项目。
我已经试过了
Router.route('/group/:_id', { name: 'group', template: 'group', waitOn: function () { return this.subscribe("groups", this.params._id); }, data: function () { return { group: Groups.findOne(this.params._id); items: Items.find({groupId: this.params._id}), } } });
但是,应该等待,如果它应该等待特定组和属于该组的项目?
您可以返回一组订阅以等待:
waitOn: function () { return [ Meteor.subscribe("groups", this.params._id), Meteor.subscribe("items", this.params._id) ] }
您可以有另一个发布function
Meteor.publish('relatedItems', function (groupId) { return Items.find({groupId: groupId}); });
并等待这两个订阅
waitOn: function () { return [ Meteor.subscribe("groups", this.params._id), Meteor.subscribe("relatedItems", this.params._id) ]; },
或者您可以添加到您现有的出版物,如下所示:
Meteor.publish('groups', function (groupId) { return [ Groups.find({_id: groupId}), Items.find({groupId: groupId}), ]; });