2013-03-15 95 views
0

在新的EmberRC1版本中,似乎我们无法从创建的对象中调用超类方法。我有一些标准的混合和视图,我用它来创建或扩展到其他对象。我有一些方法重写,但仍然需要执行超级方法,我们可以在以前的版本中使用this._super()。但在新版本中,当我创建一个对象时,这不会发生。当创建对象时this._super()问题

window.App = Ember.Application.create(); 

App.Router.map(function(){ 
    this.resource("users"); 
}); 

App.UsersView = Ember.ContainerView.extend({ 
    init : function(){ 
     this._super(); 
     this.pushObject(App.TestView.create({ 
      didInsertElement : function() { 
       this.$().append(' <br><h4>Appended at Object</h4> '); 
      } 
     })) 
    } 
}); 

App.TestView=Ember.View.extend({ 
    templateName:'test', 
    didInsertElement : function() { 
     this.$().append(' <br><h4>Appended at Class</h4> '); 
    } 
}); 

因此,这部分完全去除,或者我们可以达致这超级调用一些其他的方式?

要了解我的问题,请拨打jsfiddle

PS:我知道我可以让代码需要用其他方法名执行并调用相同的方法。但如果我有解决方案,这将是很好的。

回答

1

您仍然可以从init方法调用this._super(),它将调用父类。已经删除的内容是在对象上调用create,并传入init方法。有一个createWithMixin方法仍然允许这个功能。

有关于这个功能在这里一个非常详细的帖子:

Difference between .create() and .createWithMixins() in ember