【发布时间】:2014-06-01 06:39:46
【问题描述】:
我真的在为 Iron-router waitOn 苦苦挣扎。
我有一些订阅,我想等待,在我看来,铁路由器正在等待任何东西。
我已经设置了一些订阅 (main.js),我想在应用程序启动之前加载它们:
Meteor.subscribe("appointments");
Meteor.subscribe("business");
Meteor.subscribe("clients");
Meteor.subscribe("staff");
我已经尝试了几乎所有可能的配置,但我似乎无法让“加载程序”显示自己并等到所有订阅都准备好。我在 layoutTemplate ('layout') 中有一个辅助函数来从数据库中获取一个值,但是 findOne() 返回 undefined/null 我认为这是因为路由器没有等待订阅...
我的路由器配置。我想了解如何链接依赖项或创建要等待的依赖项。
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
waitOn: function () {
console.log('Iron router start');
this.subscribe('clients').wait();
this.subscribe('staff').wait();
this.subscribe('appointments').wait();
this.subscribe('business').wait();
this.subscribe('calendar').wait();
},
action: function() {
if (this.ready()) {
this.render('dashboard');
} else {
this.render('loading');
}
}
});
【问题讨论】:
标签: meteor iron-router