铁路由器+快速渲染,为什么这是一个无限循环



为什么这是一个无限循环?[ 铁路由器 + 快速渲染 + 火焰]

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 变量,以便我可以在前端读取它,但它实际上不起作用......我肯定做错了什么,但想首先了解为什么更新反应式变量会创建一个循环。

我也试过

if (ActiveCycle.get() !== cycle) {
    ActiveCycle.set(cycle);
}

但它也进入了一个循环...我不明白为什么

在评论中回答您的问题:

您如何订阅两个出版物:

这是我的答案:

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>

一篇不错的文章就在这里。

相关内容

最新更新