Class 在extjs 3上调用父类函数

Class 在extjs 3上调用父类函数,class,function,parent,extjs3,Class,Function,Parent,Extjs3,对于Add,我有如下extjs类: Ext.ns('Example'); Example.Form = Ext.extend(Ext.form.FormPanel, { ,initComponent:function() { // hard coded - cannot be changed from outsid var config = { items: [{ xtype: 'textfield

对于Add,我有如下extjs类:

    Ext.ns('Example');

Example.Form = Ext.extend(Ext.form.FormPanel, {

   ,initComponent:function() {
        // hard coded - cannot be changed from outsid
        var config = {
            items: [{
            xtype: 'textfield',
            fieldLabel: 'title',
            name: 'author',
            allowBlank: false
          }

         .........................

    ]
            ,buttons:[
                {
                    text:'submit'
                    ,formBind:true
                    ,scope:this
                    ,handler:this.submit
            }]
        }; // eo config object

        // apply config
        Ext.apply(this, Ext.apply(this.initialConfig, config));

        // call parent
        Example.Form.superclass.initComponent.apply(this, arguments);
    } // eo function initComponent
    /**
    * Form onRender override
    */
    ,onRender:function() {
        ..................
    } // eo function onRender
    /**
    * Reset
    */
   ,reset:function() {
        this.getForm().reset();
    } // eo function onRender
    /**
    * Load button click handler
    */
    ,onLoadClick:function() {
       ....................
    } 

    ,submit:function() {
        ........................
    } 

    ,onSuccess:function(form, action) {
       ..........................
    } 


    ,onFailure:function(form, action) {
           ......................          
    } // eo function onFailure

    ,showError:function(msg, title) {
         ........................
        });
    } 
}); 
我还有另一个编辑扩展:

Example.Form2 = Ext.extend(Example.Form, {

    ......
 });

如何从secound类的第一个类调用“onLoadClick”函数?因为我想在加载表单之前将数据加载到表单中。

如果需要将超类方法调用到子类的方法中,可以执行以下操作:

Example.Form2 = Ext.extend(Example.Form, {

    testMethod: function(){
       ...
       //call parent class method
       Example.Form2.superclass.doLoadClick.call(this);
       ...
    }
 });

这就是你的意思吗?

如果你有一个类扩展了另一个类,你可以通过在你的类定义上使用超类属性来调用“父”类方法

在下面的示例中,我们添加了一个特殊函数myspecialadd,并使其调用父类add函数

Ext.ux.myForm=Ext.extend(Ext.form.FormPanel{
...
mySpecialAdd:函数(comp,anExtraParam){
//这里有一些特殊处理
...
//调用父类add
返回Ext.ux.myForm.superclass.add.call(this,comp);
}
})
您也可以选择使用apply来代替call

Ext.ux.myForm=Ext.extend(Ext.form.FormPanel{
...
mySpecialAdd:函数(comp,anExtraParam){
//这里有一些特殊处理
...
//调用父类add
返回Ext.ux.myForm.superclass.add.apply(这个[comp]);
}
})
请注意,“this”仍然是您的新类,因此您覆盖的任何其他函数都将是从父类调用的函数,而不是父类函数

范例 Ext.form.FormPanel有一个在Ext.form.FormPanel.add中调用的onAdd方法,因此如果覆盖onAdd,则调用的是您的函数

Ext.ux.myForm=Ext.extend(Ext.form.FormPanel{
...
mySpecialAdd:函数(comp,anExtraParam){
//这里有一些特殊处理
...
//调用父类add
返回Ext.ux.myForm.superclass.add.apply(这个[comp]);
},
//即使onAdd被标记为private,您实际上仍然在这里覆盖它
//因为它在ext3中的实现方式
onAdd:功能(c){
//这将从父类(Ext.form.FormPanel)add方法调用。
...
//所以一定要处理得很好
Ext.ux.myForm.superclass.onAdd.call(this,c);
...
}
})

i在使用时会遇到这个错误:this.getContentTarget()未定义[Break On this Error](function(){var h=Ext.util,j=Ext.each;