覆盖时调用Mixin方法 [英] Call Mixin method when overriding

查看:116
本文介绍了覆盖时调用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,

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();
      });
    }
  }
});

这篇关于覆盖时调用Mixin方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆