本文介绍了覆盖时调用Mixin方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的控制器中有一个Mixin,它有特定的动作。我需要重写此操作,执行一些操作,然后调用Mixin提供的原始操作。
I've got a Mixin in my controller that has a particular action. I need to override this action, do some stuff, and then call the original action provided by the Mixin.
我该怎么做?
this._super()在这种情况下似乎不起作用(这确实是有道理的,因为这意味着调用超类的实现,而不是Mixin。)
this._super() doesn't seem to work in this case (which does make sense, as it's meant to call the superclass' implementation, not a Mixin's).
推荐答案为了调用 this._super 从 Ember.run.next 中尝试以下操作,
In order to call this._super from Ember.run.next try the following,
emberjs.jsbin/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(); }); } } });更多推荐
覆盖时调用Mixin方法
发布评论