【问题标题】:EmberJS Route event transitionEmberJS 路由事件转换
【发布时间】:2013-08-06 13:25:36
【问题描述】:

emberjs-1.0.0-rc-6.1

我的控制器:

Application.LoginController = Ember.Controller.extend({
        loginFailed: false,
        isProcessing: false,
        isSlowConnection: false,
        timeout: null,
        login: function() {
            /* some code */
        },
        success: function() {
            this.reset();
        },
        failure: function() {
            this.reset();
        },
        reset: function() {
            clearTimeout(this.get("timeout"));
            this.setProperties({
                isProcessing: false,
                isSlowConnection: false
            });
        }
    });

我的路线:

Application.LoginRoute = Ember.Route.extend({
        setupController: function(controller, model) {
            controller.reset();
        },
        events: {
        }
    });

当我第一次进入“/login”时,会调用 setupController。但是,我想在每次应用程序转换到登录时使用一个事件(如转换)来调用 controller.reset()。

有 LOG_TRANSITIONS:真

我可以在控制台中看到“Transitionned into 'login'”、“Transitionned into 'anotherPage'”,所以我想知道是否有可能在我的路由器中获取触发这些日志的事件。

喜欢:

Application.LoginRoute = Ember.Route.extend({
        setupController: function(controller, model) {
            controller.reset();
        },
        events: {
            didTransition: function(reason) {
                 controller.reset();
            }
        }
    });

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    我想知道是否有可能在我的路由器中获取触发这些日志的事件。

    您可以连接到路由的 activatedeactivate 挂钩并从那里调用控制器方法,如下所示:

    Application.LoginRoute = Ember.Route.extend({
      activate: function() {
        this.controllerFor('login').send('reset');
      },
      deactivate: function() {
        this.controllerFor('login').send('reset');
      }
    });
    

    希望对你有帮助。

    【讨论】:

    • 谢谢你的钩子!
    • 是否有“afterActivate”钩子?
    • @daniel1426 'activate' 和 'deactivate' 钩子在路由被激活/停用后触发。
    • 如果您尝试为当前活动路线加载路线怎么办?然后触发什么事件?
    猜你喜欢
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多