2013-08-29 51 views
5

最近,Ember.js was updated so that action event handlers are defined in an actions object上路由/控制器/視圖。其結果是,事件處理程序不再是在原型正常的方法。調用`從事件處理程序super`灰燼控制器上

如果你使用extend來對一個(例如)控制器進行子類化,是否仍然可以重寫然後調用超類的處理程序?

只是打電話_super不起作用:

FormController = Em.ObjectController.extend({ 
    actions: { 
     submit: function() { this.get('model').save(); } 
    } 
}); 

SpecialFormController = FormController.extend({ 
    actions: { 
     submit: function() { 
      this.set('special', true); 
      this._super(); // doesn't work 
     } 
    } 
}); 

回答

4

灰燼能夠做你正在嘗試做的。下面是一個說明如何工作的一個的jsfiddle:

http://jsfiddle.net/HzjUG/1/

App.BaseController = Em.ArrayController.extend({ 
    actions: { 
    nameAlert: function(person){ 
     window.alert('alert from BaseController: ' + person.lastName + ', ' + person.firstName); 
    } 
    } 
}); 

App.IndexController = App.BaseController.extend({ 
    actions: { 
    nameAlert: function(person){ 
     this._super(person); 
     window.alert('alert from IndexController: ' + person.lastName + ', ' + person.firstName); 
    } 
    } 
}); 

當灰燼是創建一個對象,讓他們有_Super提供給他們特別是包裝這些功能。

如果您想分享您更多的實現,我可以盡力幫助弄清楚爲什麼你的代碼是沒有的行爲示範的jsfiddle就是這樣。