Recently, Ember.js was updated so that action event handlers are defined in an actions
object on routes/controllers/views. As a result, event handlers are no longer normal methods on the prototype.
If you subclass a (for example) controller using extend
, is it still possible to override and then call the superclass's handler?
Just calling _super
doesn't work:
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
}
}
});
Ember makes it possible to do what you are trying to do. Here is a JSFiddle that demonstrates how this works:
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);
}
}
});
When Ember is creating an object, it specially wraps these functions so that they have _super available to them.
If you'd like to share more of your implementation, I can try to help figure out why your code is not behaving the way the JSFiddle demonstration is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With