0

有谁知道如何在 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);
    }
});
4

2 回答 2

0

试试Ext.Panel.superclass.initComponent.call(this)吧。

于 2013-02-19T19:01:47.087 回答
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);
}

但他们都是丑陋的imo。

于 2013-02-19T22:32:05.373 回答