Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Meteor中进行顺序订阅(iron:路由器)_Meteor_Iron Router - Fatal编程技术网

如何在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已经有多个答案了。您还可以阅读以下内容: