gpt4 book ai didi

ember.js - 覆盖时调用 Mixin 方法

转载 作者:行者123 更新时间:2023-12-04 07:54:08 25 4
gpt4 key购买 nike

我的 Controller 中有一个具有特定操作的 Mixin。我需要覆盖这个 Action ,做一些事情,然后调用 Mixin 提供的原始 Action 。

我怎样才能做到这一点?
this._super()在这种情况下似乎不起作用(这确实有意义,因为它意味着调用父类(super class)的实现,而不是 Mixin 的实现)。

最佳答案

如需调用this._super来自 Ember.run.next尝试以下,

http://emberjs.jsbin.com/docig/3/edit

App.MyCustomMixin = Ember.Mixin.create({
testFunc:function(){
alert('original mixin testFunc');
},
actions:{
testAction:function(){
alert('original mixin testAction');
}
}
});

App.IndexController = Ember.Controller.extend(App.MyCustomMixin,{
testFunc:function(){
alert('overriden mixin testFunc');

var orig_func = this._super;
Ember.run.next(function(){
orig_func();
});
},
actions:{
test:function(){
this.testFunc();
},
testAction:function(){
alert('overriden mixin testAction');
var orig_func = this._super;
Ember.run.next(function(){
orig_func();
});
}
}
});

关于ember.js - 覆盖时调用 Mixin 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21658627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com