如何在Meteor中进行顺序订阅(iron:路由器)
例如,我必须这样做:如何在Meteor中进行顺序订阅(iron:路由器),meteor,iron-router,Meteor,Iron Router,例如,我必须这样做: Router.route('/threadList', { waitOn: function () { return Meteor.subscribe('threads', Meteor.userId); }, data: function() { threads = Threads.find(); _.each(threads, function(thread) { _.each(thread.comments, function(
Router.route('/threadList', {
waitOn: function () {
return Meteor.subscribe('threads', Meteor.userId);
},
data: function() {
threads = Threads.find();
_.each(threads, function(thread) {
_.each(thread.comments, function(commentId) {
Meteor.subscribe('comments', commentId);
})
})
}
我不知道如何在Meteor中做这类事情你可以查看包 在发布代码中执行被动连接 只需将其添加到您的项目中:
meteor add reywood:publish composite
然后,请按如下方式发布:
Meteor.publishComposite('publishName', {
find: function() {
return Threads.find({userId: this.userId});
},
children: [
{
find: function(thread) {
return Comments.find({threadId: thread._id});
}
}
});
让订阅使用一个注释id数组而不是单个id不是更容易、更有效吗?然后你就可以建立阵列并只订阅一次。这个问题一直在出现,关于stackoverflow已经有多个答案了。您还可以阅读以下内容: