重写时调用 Mixin 方法



我的控制器中有一个具有特定操作的 Mixin。我需要覆盖此操作,执行一些操作,然后调用 Mixin 提供的原始操作。

我该怎么做?

在这种情况下,this._super()似乎不起作用(这确实有意义,因为它旨在调用超类的实现,而不是 Mixin 的)。

为了从Ember.run.next调用this._super,请尝试以下操作,

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

最新更新