2013-08-06 54 views
4

emberjs-1.0.0-RC-6.1EmberJS路線事件轉換

我的控制器:

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: { 
     } 
    }); 

當我去 「/登錄」 爲第一次調用setupController。不過,我想每次使用事件(如轉換)來調用controller.reset()應用程序轉換爲登錄。

隨着 LOG_TRANSITIONS:真

我可以看到「Transitionned到‘登錄’」,在控制檯「Transitionned到‘anotherPage’」,所以我想知道是否有可能獲得事件,觸發那些日誌,在我的路由器中。

像:

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

回答

3

我想知道是否有可能得到這觸發這些日誌,在我的路由器的事件。

您可以掛接到該路由的activatedeactivate掛鉤,並從那裏調用控制器方法,就像這樣:

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

希望它能幫助。

+0

謝謝你的掛鉤! –

+0

有沒有「afterActivate」掛鉤? – daniel1426

+0

@ daniel1426激活/取消激活路線後,激活「激活」和「停用」掛鉤。 –