Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86587
  • 博文数量: 49
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 450
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-28 15:27
文章分类

全部博文(49)

分类: HTML5

2016-12-26 16:07:36

ExtJS中有事需要获得Form表单的值,根据API可知 getValues() 可以获得单签Form表单中所有 Name 值的一个对象。
片段代码如下:
var formValues=formpanel.getForm().getValues(); //获取表单中的所有Name键/值对对象
alert(formValues["firstname"]); //输出表单中 firstname 字段的值
console.log(formValues); //输出结果是表单中的所有Name键/值对的一个对象
整体代码如下:
/**
 * Created with JetBrains PhpStorm.
 * User: std
 * Date: 13-6-9
 * Time: 上午10:55
 * To change this template use File | Settings | File Templates.
 */

Ext.onReady(function(){
    //
    var formpanel=Ext.create("Ext.form.Panel",{
        title:"Dynamic Form",
        draggable:true,
        frame:true,
        width:330,
        height:255,
        //autoHeight:true,
        bodyPadding:"7 5 7 5",
        items:[{
            xtype:"fieldset",
            frame:true,
            title:"Contact Information",
            //defaultType: 'textfield',
            defaults:{xtype:"textfield",labelWidth:80,labelAlign:"right",width:280},
            items:[{
                fieldLabel:"First Name",emptyText:"First Name",name:"firstname"
            },{
                fieldLabel:"Last Name",emptyText:"Last Name",name:"lastname"
            },{
                fieldLabel:"Company",emptyText:"Company",name:"company"
            },{
                fieldLabel:"Email",emptyText:"Email",name:"email"
            },{
                fieldLabel:"State",xtype:"combobox",emptyText:"请选择",name:"state"
            },{
                fieldLabel:"Date of Birth",xtype:"datefield",emptyText:"请选择日期",name:"dateofbirth"
            }]
        }],
        buttons:[
            {text:"确定",handler:function(){
                var formValues=formpanel.getForm().getValues();
                alert(formValues["firstname"]);
                console.log(formValues);
            }},
            {text:"取消"}
        ]
    });

    formpanel.render(Ext.getBody());
});
阅读(691) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~