EmberJS路由事件转换 [英] EmberJS Route event transition

查看:118
本文介绍了EmberJS路由事件转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

emberjs-1.0.0-rc-6.1

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()每次应用程序转换为登录。

When I go to "/login" for the first time, setupController is called. However, I would like to use a event (like transition) to call controller.reset() everytime Application transition into login.

使用
LOG_TRANSITIONS:true

With LOG_TRANSITIONS: true

我可以在控制台中看到转换为登录,转换为另一个页面,所以我想知道是否可以获取事件触发这些日志,在我的路由器。

I can see "Transitionned into 'login'", "Transitionned into 'anotherPage'" in the console, so I would like to know if it's possible to get the event which trigger those logs, in my router.

喜欢:

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


推荐答案


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

I would like to know if it's possible to get the event which trigger those logs, in my router.

您可以挂接到路由的激活停用挂钩并从中调用控制器方法,如下所示:

You can hook into to the route's activate and deactivate hooks and call the controller methods from there, like this:

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

希望有帮助。

这篇关于EmberJS路由事件转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆