Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Extjs中获取类实例?_Javascript_Extjs - Fatal编程技术网

Javascript 如何在Extjs中获取类实例?

Javascript 如何在Extjs中获取类实例?,javascript,extjs,Javascript,Extjs,我定义了一个类“IMS.SellMgt.testForm”。当我单击“提交”按钮时,我想得到“var test=this.formPanel;”,为什么测试是空的?如果我想得到这个。formPanel,我该怎么办?谢谢 Ext.define('IMS.SellMgt.testForm', { formPanel: null, LoadForm: function () { this.formPanel = new Ext.form.Panel({

我定义了一个类“IMS.SellMgt.testForm”。当我单击“提交”按钮时,我想得到“var test=this.formPanel;”,为什么测试是空的?如果我想得到这个。formPanel,我该怎么办?谢谢

    Ext.define('IMS.SellMgt.testForm', {
    formPanel: null,
    LoadForm: function () {
            this.formPanel = new Ext.form.Panel({
            renderTo: 'form-ct',
            frame: true,
            title: 'XML Form',
            width: 300,
            items: [{
                xtype: 'fieldset',
                title: 'Contact Information',
                defaultType: 'textfield',
                items: [{
                    fieldLabel: 'First Name',
                    emptyText: 'First Name',
                    name: 'first'
                }
            ]
            }],
            buttons: [{
                text: 'Submit',
                handler: function () {
                    var test = this.formPanel;
                        }
            }]
        });
    }
});

Ext.onReady(function () {
    var frmTest = Ext.create('IMS.SellMgt.testForm', {});
    frmTest.LoadForm();
});
尝试以下方法:

......
handler: function () {
    var test = this.findParentByType(Ext.form.FormPanel);
}
....

handler
是为按钮指定单击事件侦听器的一种更简单的方法。因为它是简写的,所以有一些缺点

使用
处理程序
,函数的上下文始终是按钮。换句话说,
处理函数中的这个
是按钮,而不是表单

要使
成为您的类,请使用具有指定范围的侦听器:

buttons: [{
    text: 'Submit',
    listeners: {
        click: function() {
            this.formPanel; // will work now
            ...
        },
        scope: this // this is the key
    }
}]
您还可以使用
up
查找表单:

handler: function() {
    var form = this.up('form');
    ...
}