Flowrouter订阅

时间:2017-02-09 07:06:44

标签: meteor publish-subscribe flow-router

这就是我的flowrouter的样子, 我尝试了下面显示的所有三个选项:但无法订阅

import {CompanySettings} from '../imports/api/companysettingsMaster.js';
// And imported the api also..
FlowRouter.route('/', {
  name: 'home',
  subscriptions: function() {
    // 1.
    return this.register('companySettings', Meteor.subscribe('companySettings'));
    // 2.
    this.register('CompanySettings', Meteor.subscribe('companySettings'));
    // 3.
    return Meteor.subscribe('companySettings');
  },
  action: function() {

    var themeSettings = CompanySettings.findOne({
      "companyId": 101
    });
    if (themeSettings) {
      console.log(themeSettings);
      var scaleProcess = themeSettings.generalSettings.scaleProcess;

      if (scaleProcess == 'retail')
        BlazeLayout.render("retailMainLayout", {
          content: "homepages"
        });
      else {
        BlazeLayout.render("WSEmainLayout", {
          content: "homepages"
        });
      }
    } else {
      console.log('no themeSettings');
    }

  }
});

但是,最后没有得到文件..任何建议..提前谢谢

1 个答案:

答案 0 :(得分:2)

我在flowrouter中得到了订阅的答案,如下所示:

FlowRouter.route('/', {
    waitOn: function () {
       return Meteor.subscribe('companySettings');
    },    
});

这里companySettings是mongodb中的集合名称