Ember.js 呼叫“a”;“基类”;来自扩展对象的方法
假设我有这个:Ember.js 呼叫“a”;“基类”;来自扩展对象的方法,ember.js,Ember.js,假设我有这个: App.ControllerMixin = Ember.Mixin.create({ setupController : function (entry) { ... } }); App.BaseEditController = Ember.ObjectController.extend(App.ControllerMixin, { startEditing: function () { ... this.
App.ControllerMixin = Ember.Mixin.create({
setupController : function (entry) {
...
}
});
App.BaseEditController = Ember.ObjectController.extend(App.ControllerMixin, {
startEditing: function () {
...
this.setupController(entry);
},
});
App.ServicesEditController = App.BaseEditController.extend(App.ServicesMixin, {
setupController : function (entry) {
}
});
如何从
servicesditcontroller.setupController
调用ControllerMixin.setupController
?您可以使用this.\u super()
从超类调用方法。通常,最好将此调用添加到要重写的每个方法中
App.ServicesEditController = App.BaseEditController.extend(App.ServicesMixin, {
setupController : function (entry) {
this._super(entry);
}
});
根据我的建议,在每个重写方法中添加此调用,这是视图的Mixin示例。如果你的Mixin覆盖了didInsertElement,你应该总是添加一个对this的调用如果应用了多个mixin,这将确保调用“所有”didInsertElement实现。
App.SomeViewMixin = Ember.Mixin.create({
didInsertElement : function(){
this._super();
// ... perform your logic
}
});
让我直截了当地说:你是说从
setupController
中调用的this.\u super(entry)
将自动调用super类上的setupController
方法吗?这意味着,\u super
调用名为调用它的方法的方法?魔法!:)如果重写控制器中的Mixin方法,则此.\u super()似乎不会调用Mixin方法。我该怎么做?