努力等待订阅和多个订阅 [英] struggling to wait on subscriptions and multiple subscriptions
问题描述
我真的在为铁路由器waitOn苦苦挣扎.
i am really struggling with the iron-router waitOn.
我有很多要等待的订阅,在我看来铁路由器正在等待任何事情.
I have a number of subscriptions that i would like to waitOn, it doenst seem to me that iron router is waiting on anything.
我已经设置了许多订阅(main.js),我希望在应用程序启动之前加载这些订阅:
I have setup a number of subscriptions (main.js), which i would like to load before the application starts:
Meteor.subscribe("appointments");
Meteor.subscribe("business");
Meteor.subscribe("clients");
Meteor.subscribe("staff");
我已经尝试了几乎所有可能的配置,但似乎无法让"loader"显示出来并等待所有订阅准备就绪.我在layoutTemplate('layout')中有一个辅助函数,用于从数据库中获取值,但是findOne()返回undefined/null,我认为这是因为路由器尚未等待订阅...
I have tried almost every configuration i possibly can but i cannot seem to get the "loader" to show itself and wait till all the subscriptions are ready. I have a helper function in the layoutTemplate ('layout') to get a value from the database however findOne() returns undefined/null i assume this is because the router has not waited on the subscriptions...
我的路由器配置.我想了解如何链接依赖项或创建依赖项以等待.
My router configuration. I would like to understand how i can chain the dependencies or create the dependencies to wait.
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');
}
}
});
推荐答案
尝试像这样更改waitOn
部分.另外,我认为您可以从main.js
文件中删除订阅,并在该特定路由的路由器waitOn
函数中写入所需/相关的订阅.
Try changing the waitOn
section like this. Also, I think you can remove the subscriptions from the main.js
file and write the required/dependent subscriptions in the router's waitOn
function for that particular route.
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
waitOn: function () {
console.log('Iron router start');
return [
Meteor.subscribe('clients'),
Meteor.subscribe('staff'),
Meteor.subscribe('appointments'),
Meteor.subscribe('business'),
Meteor.subscribe('calendar')
]
},
action: function() {
if (this.ready()) {
this.render('dashboard');
} else {
this.render('loading');
}
}
});
这篇关于努力等待订阅和多个订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!