今天做Ext的例子,怎么也不能得到CheckboxGroup中的实际,后来经过网上相关的一些资料,终于有了进展:
//兴趣爱好
var ckHobby1 = new Ext.form.Checkbox({
name:"ckHobby", //这几个复选框的值一定要相同
boxLabel:"游泳", //显示值
inputValue:"游泳"
});
var ckHobby2 = new Ext.form.Checkbox({
name:"ckHobby",
boxLabel:"钓鱼",
inputValue:"钓鱼"
});
var ckHobby3 = new Ext.form.Checkbox({
name:"ckHobby",
boxLabel:"散步",
inputValue:"散步"
});
var ckHobby4 = new Ext.form.Checkbox({
name:"ckHobby",
boxLabel:"玩游戏",
inputValue:"玩游戏"
});
var gpHobbys = new Ext.form.CheckboxGroup({
name:"wkHobbys",
id:"hobby",
fieldLabel:"兴趣爱好",
items:[ckHobby1,ckHobby2,ckHobby3,ckHobby4],
width:250
});
var hobbys = new Array(); //定义一个数组
var subBut = new Ext.Button({ //提交按钮
text:"提交",
handler:function(){
var FileItype=f.getForm().findField('wkHobbys').getValue(); //得到组合框
for(var i=0; i<FileItype.length; i++){
hobbys[i] = FileItype[i].inputValue; //遍历组合到数组中
}
f.getForm().submit({ //当提交时执行
success:function(form,action){
Ext.Msg.alert("提示",action.result.msg);
},
failure:function(){
Ext.Msg.alert("信息","对不起,您提交信息失败");
setTimeout(function(){ //设置弹出窗口3秒后自动消失
Ext.Msg.hide()
},3000);
}
});
}
});
var f = new Ext.form.FormPanel({ //定义FormPanel
url:"<%=basePath%>login/workerAction!addWorkerHobbyInfos",
method:"post", //指定出表单提交的路径和方法
baseParams:{hobbys:hobbys},
renderTo:"work",
title:"新增员工",
width:700,
labelAlign:"right",
autoHeight:true,
frame:true,
items:[userName,userPassword,sex,birthday,gpHobbys,loveNum,address,timeWork,myself,photo],
buttons:[subBut,resBut],
buttonAlign:"center"
});
在后台接值:
String[] hobbys = request.getParameterValues("hobbys");
System.out.print("兴趣: ");
for(int i=0; i<hobbys.length; i++){
System.out.print(hobbys[i]+ " 、");
}
这里是先在前台得到每一个实际的值,放到一个数组,再把数组用隐藏表单域的形式,传递到后台,在后台再进行遍历,得到每一个checkbox的值