覆盖时调用Mixin方法

编程入门 行业动态 更新时间:2024-10-14 06:24:34
本文介绍了覆盖时调用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方法

本文发布于:2023-08-04 09:12:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1295007.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时调   方法   Mixin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!