2013-08-29 2 views
5

최근에 경로/컨트롤러 /보기에서 Ember.js was updated so that action event handlers are defined in an actions object입니다. 결과적으로 이벤트 핸들러는 더 이상 프로토 타입에 대한 정상적인 메소드가 아닙니다.Ember 컨트롤러의 이벤트 처리기에서 '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

엠버는 당신이 뭘 하려는지 할 것을 가능하게한다. 그들은 그들에게 _super 가능한 있도록

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

엠버는 객체를 생성, 그것은 특별히 이러한 기능을 래핑 : 여기이 작동 방법을 보여주는 JSFiddle이다.

더 많은 구현을 공유하고 싶다면 코드가 JSFiddle 데모와 다른 방식으로 작동하지 않는 이유를 파악할 수 있습니다.

관련 문제