【问题标题】:Totally confused about this.next() in Meteor iron-router对 Meteor Iron-router 中的 this.next() 完全感到困惑
【发布时间】:2014-11-01 20:15:31
【问题描述】:

我升级到 Meteor 1.0,安装了最新的 iron-router 包,尝试运行我的应用程序并在我的控制台日志中收到了这个很好的警告:

路由调度从未渲染。您是否忘记调用 this.next() 一个 onBeforeAction?

所以我尝试根据新版本修改我的路线。

this.route('gamePage', {
        path: '/game/:slug/',
        onBeforeAction: [function() {
            this.subscribe('singlePlayer', this.params.slug).wait();
            var singlePlayer = this.data();
            if (singlePlayer) {
                if (singlePlayer.upgrade) {
                    this.subscribe('upgrades', this.params.slug).wait();
                    this.next();
                }
                this.next();
            }
            this.next();
        }],
        data: function() {
            return Games.findOne({slug: this.params.slug});
        },
        waitOn: function() { return [Meteor.subscribe('singleGame', this.params.slug)]}
    });

我该如何解决这个问题? 任何帮助将不胜感激。

【问题讨论】:

    标签: javascript meteor iron-router


    【解决方案1】:

    尝试删除所有 .wait()s 并删除 onBefore 函数周围的数组。

    用新的 API this.next() 替换 .wait()

    【讨论】:

    • 谢谢!这样可行!我需要 3 x this.next() 还是在函数结束时只需要一次?
    • 第一个if 可能不需要它。试一试并报告。
    • 这对我有用:if (singlePlayer) { if (singlePlayer.upgrade) { this.subscribe('upgrades', this.params.slug).wait(); } } this.next(); 你能解释一下我应该把this.next() 放在哪里吗?试错法有点令人沮丧。
    • 很抱歉。基本上,如果您的 onBeforeonRun 不会导致运行 Router.go(),则您需要它。你的没有。 IronRouter onBefore 将运行它遇到的第一个命令然后停止...除非您调用 this.next()。然后它会做同样的事情(运行然后停止),直到您到达 onBefore/onRun 逻辑的末尾或调用 Router.go
    猜你喜欢
    • 2015-05-12
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    • 2013-04-03
    • 1970-01-01
    相关资源
    最近更新 更多