【发布时间】:2015-04-10 10:03:17
【问题描述】:
我看到以前的旧帖子中旧版本的 Iron-router 确实 wait() :
before: function() {
// let's make sure that the topPosts subscription is ready and the posts are loaded
if (this.data()) {
// we can then extract the userIds of the authors
var userIds = this.data().map(function(p) { return p.userId });
// and add the authors subscription to the route's waiting list as well
this.subscribe('authors', userIds).wait(); **<--- this guy!**
}
}
以上来自https://www.discovermeteor.com/blog/reactive-joins-in-meteor/
如果我将 wait() 添加到我的 OnBeforeAction 订阅中,我会收到以下错误:
You called wait() after calling ready() inside the same computation tree.
You can fix this problem in two possible ways:
1) Put all of your wait() calls before any ready() calls.
2) Put your ready() call in its own computation with Deps.autorun.
我的等待是
waitOn: function() {
return Meteor.subscribe('weeks', this.params.league);
},
和 OnBeforeAction
onBeforeAction: function() {
if (this.ready()) {
// we can now get the latest (first in the list) week
var week = SheetData.find().fetch()[0].week;
this.subscribe('standings', this.params.league, week).wait();
this.next();
}
}
如果我删除了 wait(),渲染模板会在我的订阅准备好之前启动。建议的修复似乎不适用。我错过了什么?
【问题讨论】:
标签: iron-router