【问题标题】:How to do sequential subscription in Meteor(iron:router) [duplicate]如何在 Meteor(铁:路由器)中进行顺序订阅 [重复]
【发布时间】:2015-08-12 14:32:28
【问题描述】:

例如,我必须这样做:

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 中做这种事情

【问题讨论】:

  • 让订阅接受评论 ID 数组而不是单个 ID 不是更简单、更高效吗?然后你可以建立数组并且只订阅一次。
  • 这个问题一直出现,并且在stackoverflow上已经有多个答案。你也可以阅读:discovermeteor.com/blog/reactive-joins-in-meteor

标签: meteor iron-router


【解决方案1】:

您可以查看包裹publish-composite

在您的发布代码中进行反应式连接。

只需将其添加到您的项目中: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});
            }
        }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 2016-03-01
    • 2015-06-01
    • 2017-01-19
    • 1970-01-01
    • 2020-05-05
    • 2016-05-10
    相关资源
    最近更新 更多