【问题标题】:Meteor subscribe multiple publication in single lineMeteor 单行订阅多个发布
【发布时间】:2015-11-20 07:32:58
【问题描述】:

我的问题很简单。我订阅了onCreated 的多个出版物。单行怎么做?

Template.Name.onCreated(() => {
  Template.instance().subscribe('countries');
  Template.instance().subscribe('pincode');
});

类似

Template.Name.onCreated(() => {
  Template.instance().subscribe(['countries','pincode']);
});

【问题讨论】:

    标签: meteor


    【解决方案1】:

    也许您想创建一个组合出版物

    Meteor.publish('combined', functinon() {
        return [
            Countries.find(),
            Pincodes.find()
        ];
    })
    

    然后订阅它

    Template.Name.onCreated(() => {
        Meteor.subscribe('combined');
    });
    

    【讨论】:

    • 没有。就我而言,我可以将pincodes 用于其他模板。我需要合并订阅而不是发布。
    • 好吧,您仍然可以将其作为单独的出版物。为什么你需要把它放在一行上?
    • 我认为这样做不会带来任何性能优势,但如果你找到了办法,请告诉我
    【解决方案2】:

    你可以这样做:

    ['countries','pincode'].forEach(x => {Template.instance().subscribe(x);});

    虽然我同意@durrrr,但不会有任何性能优势。我自己将其保留为两条单独的行。

    【讨论】:

      猜你喜欢
      • 2018-03-07
      • 1970-01-01
      • 2016-11-29
      • 2017-11-30
      • 2013-11-18
      • 2016-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多