ExtJS中怎样获取Form表单中的每一项的值
推荐于2016-07-06 · 知道合伙人互联网行家
关注
展开全部
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());
});
片段代码如下:
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());
});
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询