2013-02-19 21 views
0

有谁知道如何在ext js 3.4中成功调用超类? 在我的示例代码中,我似乎无法获得在面板上工作的超类。如何在变量内调用ext js 3.4中的超类

MyWindow = Ext.extend(MyWindowUi, { 
    initComponent: function() { 
     MyWindow.superclass.initComponent.call(this); 
     this.createTextField(); 
    }, 
    createTextField : function() { 
     var p = new Ext.Panel({ 
      title: 'somepanel', 
      initComponent: function() { 
       console.log('init component'); 
       console.log(this); 
       this.superclass.initComponent.call(this); //NOT WORKING?? 
      } 
     }); 
     this.add(p); 
    } 
}); 

回答

0

改为尝试Ext.Panel.superclass.initComponent.call(this)

+0

我尝试使用超类,但没有呈现面板。 Ext.Panel.prototype.initComponent.call(this);为我工作。 – chriscrossweb 2013-03-25 19:58:40

0

它不起作用,因为在创建p时不调用Ext.Panel的initComponent。如果你打算用上一个方法的超类调用重写一个方法,那么如果不需要使用范围技巧,Ext.extend将会更清晰。

你也可以这样做:

createTextField : function() { 
    var p = new Ext.Panel({ 
     title: 'somepanel' 
    }), 
    oldInit = p.initComponent; 

    p.initComponent = function() { 
     console.log('init component'); 
     console.log(this); 
     oldInit.call(this); 
    } 

    this.add(p); 
} 

或者类似的东西:

createTextField : function() { 
    var p = new Ext.Panel({ 
     title: 'somepanel', 
     initComponent: function() { 
      console.log('init component'); 
      console.log(this); 
      Ext.Panel.prototype.initComponent.call(this); 
     } 
    }); 
    this.add(p); 
} 

但他们都是丑陋的海事组织。

+0

谢谢!超,选项:Ext.Panel.prototype.initComponent.call(this);很棒! – chriscrossweb 2013-03-25 19:54:24