您的位置:首页 > Web前端 > JavaScript

extjs表单中动态添加items

2016-06-22 10:09 423 查看
items:[
var exceptionNumber = 1;
var exceptionHandling =new String;
{
xtype: 'fieldset',
title: '异常处理',
id:'exceptionHand',
defaultType: 'textfield',
width:400,
items:[
{

xtype:"button",
text:"增加异常情况",
handler : function() {
exceptionNumber++;
var exceptionForm = Ext.getCmp("exceptionHand");
var configItem=[{
xtype:'fieldcontainer',
layout:'hbox',
items:[
{
xtype:'textfield',
labelAlign:'top',
id:'exceptionContex'+exceptionNumber,
name: 'exceptionContex'+exceptionNumber,
fieldLabel: '第'+exceptionNumber+'条异常内容',

},
{
xtype:'textfield',
labelAlign:'top',
id:'solvingMethod'+exceptionNumber,
name: 'solvingMethod'+exceptionNumber,
fieldLabel: '处理方式',

}

]
}];
exceptionForm.add(configItem[0]);
exceptionForm.doLayout();
}
},
{
xtype:'fieldcontainer',
layout:'hbox',
labelAlign:'top',
items:[
{
xtype:'textfield',
labelAlign:'top',
id:'exceptionContex1',
name: 'exceptionContex1',
fieldLabel: '第1条异常内容',
},
{
xtype:'textfield',
labelAlign:'top',
id:'solvingMethod1',
name: 'solvingMethod1',
fieldLabel: '处理方式',
}
]
}
]
},
buttons:[

{
text:"添加",
handler:function(){
exceptionHandling ="{";
for(var i=1;i<=exceptionNumber;i++){
exceptionValue = Ext.getCmp('exceptionContex'+i).getValue();
solveMethod = Ext.getCmp('solvingMethod'+i).getValue();
exceptionHandling = exceptionHandling+'"'+exceptionValue+
'":"'+solveMethod+'",';
if(i==exceptionNumber){
exceptionHandling = exceptionHandling.substring(0,(exceptionHandling.length-1));
}
}
exceptionHandling = exceptionHandling + "}";

alert(exceptionHandling);
form.getForm().submit({
params:{'testIFCObject.exceptionHandling':exceptionHandling},
url:"TestIFCObjectAdd.action",
waitMsg:"请稍等,正在添加",
success:function(form,action){
Ext.MessageBox.alert("提示信息","添加成功");
store.reload();
win.close(this);
},
failure:function(form,action){
Ext.MessageBox.alert("提示信息",action.result.msg);
}
});

}
},
{
text:"重置",handler:function(){
form.getForm().reset();
}
}
]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: