从javascript Ext.form.FormPanel获取值并设置为变量

时间:2012-08-28 08:28:16

标签: javascript variables formpanel

我遇到以下javascript问题:

var stereo_form =new Ext.form.FormPanel({
        id: "stereoInfo_panel",
        autoDestroy:true,
        frame: true,
        width: 410,
        items:[{
            xtype: 'textfield',
            fieldLabel: 'DEM Resolution',
            name: 'resolution',
            value: '0.005' //sets a default value

        },{
            xtype: 'textfield',
            fieldLabel: 'Pyramid Level',
            name: 'matching',
            value: '0' //sets a default value

        },{
            xtype: 'textfield',
            fieldLabel: 'Size of DEM',
            name: 'size',
            value: '50.00' //sets a default value

        }],
            buttons: [{
                text: 'Confirm',
                handler: function()
                        {
                               // user1 = value of resolution field
                                                // user2 = value of matching field
                                                // user3 = value of size field
                            w.close();
                        }

        }]
    }); 

    var w =new Ext.Window({
        id: "stereoInfo_win",
        title: "Stereo Reconstruction Parameters",
        layout: 'form',
        height: 152,
        width: 415,
        items: stereo_form

    });

所以我需要在按下“确认”按钮时从表单字段分辨率,匹配和大小中分配三个user1,user2和user3变量,我该怎么做?

詹姆斯

1 个答案:

答案 0 :(得分:1)

试试这个:

var w = new Ext.Window({
        id: "stereoInfo_win",
        title: "Stereo Reconstruction Parameters",
        layout: 'form',
        height: 152,
        width: 415,
      items: {
        xtype: 'form',
        id: "stereoInfo_panel",
        frame: true,
        width: 410,
        items:[{
            xtype: 'textfield',
            fieldLabel: 'DEM Resolution',
            name: 'resolution',
            value: '0.005' //sets a default value

        },{
            xtype: 'textfield',
            fieldLabel: 'Pyramid Level',
            name: 'matching',
            value: '0' //sets a default value

        },{
            xtype: 'textfield',
            fieldLabel: 'Size of DEM',
            name: 'size',
            value: '50.00' //sets a default value

        }],
            buttons: [{
                text: 'Confirm',
                handler: function(btn)
                 {

                 // console.log(Ext.getVersion()); // uncomment to know your extjs version

                 // traverse to the form object, then get the fields values
                 var values = btn.findParentByType('form').getForm().getValues();

                  user1 = values['resolution'];
                 user2 = values['matching'];
                 user3 = values['size'];

                 // traverse up again to the window object
                 btn.findParentByType('window').close();
             }

        }]
    }

});