4

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: true

コンソールに「Transitionned into 'login'」、「Transitionned into 'anotherPage'」が表示されるので、ルーターでこれらのログをトリガーするイベントを取得できるかどうかを知りたいです。

お気に入り :

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

1 に答える 1

3

ルーターで、これらのログをトリガーするイベントを取得できるかどうかを知りたいです。

次のように、ルートactivatedeactivateフックにフックして、そこからコントローラー メソッドを呼び出すことができます。

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

それが役に立てば幸い。

于 2013-08-06T14:05:25.867 に答える