为什么这是一个无限循环? [Iron Router + Fast Render + Blaze]
Router.route("/:cycle_uri", {
name: "cycle"
,template: "home"
,onBeforeAction: function () {
console.log("is there a loop here?") // this is what confirms that it's a continuous loop
var cycle = Cycles.findOne({
"uri": this.params.cycle_uri
});
if (typeof cycle === "undefined") {
this.render("notFound"); return;
} else {
ActiveCycle.set(cycle); // if I remove this, there is no continuous loop anymore... but if I remove it I don't see how to have this info in the client
this.render("home");
}
}
,waitOn: function () {
Meteor.subscribe('featuredListsPub', {
'program_id': this.params.cycle_uri
});
}
,fastRender: true
});
我试图更新ActiveCycle变量,所以我可以在前端读取它,但它实际上没有工作......我当然做错了什么,但我想首先理解为什么更新反应var正在创建一个循环。
我也试过
if (ActiveCycle.get() !== cycle) {
ActiveCycle.set(cycle);
}
但它也进入循环......我不明白为什么
答案 0 :(得分:1)
在评论中提问:
您如何订阅两份出版物:
这是我的回答:
waitOn: function () {
return [
Meteor.subscribe('subscription1'), Meteor.subscribe('subscription2')
];
}
但是,我强烈建议:
祝你好运!
模板级订阅的示例:
Template.templatename.onCreated(function () {
Template.autorun(function () {
var subscription = Meteor.subscribe('some_publication');
if (subscription.ready()) {
// do something
}
});
});
并在模板中
<template name="templatename">
{{#if Template.subscriptionsReady}}
<div>Your Template here...</div>
{{else}}
<p>Loading...</p>
{{/if}}
</template>
一篇好文章是正确的here。