如何从Ext表单中获取值

Pam*_*bul 9 extjs extjs4

实际上我有一个ExtJs脚本来创建一个窗口,下面有一个窗口.

var frmAccount = Ext.create('Ext.form.Panel',{
    bodyPadding: 5,
    frame  : true,
    items    :[
    {
        xtype       : 'textfield',
        fieldLabel  : 'Account Number',
        name        : 'accountNum'
    },{
        xtype       : 'textfield',
        fieldLabel  : 'Company',
        name        : 'company'
    },{
        xtype       : 'textfield',
        fieldLabel  : 'Office',
        name        : 'office'
    },{
        xtype       : 'textareafield',
        fieldLabel  : 'Address',
        name        : 'address',
        width       : 350
    },{
        xtype       : 'textfield',
        fieldLabel  : 'City',
        name        : 'city'
    },{
        xtype       : 'textfield',
        fieldLabel  : 'Country',
        name        : 'nation'
    }]
});

var winAddAccount = Ext.create('widget.window',{
    id     : 'addAccount',
    title  : 'Filter Record',
    width  : 400,
    height : 300,
    modal  : true,
    closeAction    : 'hide',
    items  : frmAccount,
    layout : 'fit',
    bodyPadding: 5,
    buttons:[
    {
        text    : 'Find',
        handler: function(){
            //console.log(form value);
        }
    },
    {
        text    : 'Cancel',
        handler: function(){
            winAddAccount.hide();
        }
    }
    ]
});
Run Code Online (Sandbox Code Playgroud)

我只想在点击"查找"按钮后从表单中获取值.但是,在点击"查找"按钮后,我不知道从表单中获取值.希望我可以console.log在处理程序上看到脚本的值.请帮助我解决或提出一个想法.谢谢.

sra*_*sra 28

试试这个

text    : 'Find',
handler: function(btn){
    var win = btn.up('window'),
        form = win.down('form');
    console.log(form.getForm().getValues());
}
Run Code Online (Sandbox Code Playgroud)

此外,我建议您查看sencha提供的教程,并查看API,其中还包含大量示例

要仅获取特定字段的值(此示例假定该字段存在!)

text    : 'Find',
handler: function(btn){
    var win = btn.up('window'),
        form = win.down('form');
    console.log(form.getForm().findField('NamePropertyValue').getSubmitValue() /*or call getSubmitData() or just getValue()*/);
}
Run Code Online (Sandbox Code Playgroud)