ajax jsonObject struts2
1前台通过jquery与struts2action交互
$.ajax({
url:"<%=rootPath%>/index!comInitGroupEdit.action?groupid="+groupId,
type:"post",
dataType:"json",
success:function(json){
varallGroupArray=json.allGroupArray;
vargroupByIdArray=json.groupByIdArray;
$.each(allGroupArray,function(i){
//window.alert("groupByIdArray[0].PARID:"+groupByIdArray[0].PARID+"allGroupArray[i].ID:"+allGroupArray[i].ID);
if(groupByIdArray[0].PARID==allGroupArray[i].ID){
tempHTML1="<optionselectedvalue="+allGroupArray[i].ID+">"+allGroupArray[i].NAME;
}else{
tempHTML1="<optionvalue="+allGroupArray[i].ID+">"+allGroupArray[i].NAME;
}
});
$("#groupName").val(groupByIdArray[0].NAME);
$("#oldGroupName").val(groupByIdArray[0].NAME);
}
});
2后天通过struts2action取数据
publicStringcomInitGroupEdit(){
StringqueryAllGroup="SELECTtg.group_idID,tg.group_nameNAMEFROMtb_iap_tgt_grouptgORDERBYtg.group_idASC";
StringqueryGroupByid="SELECTtg.group_idID,tg.group_id_parentparId,tg.group_nameNAMEFROMtb_iap_tgt_grouptgWHEREtg.group_id="+groupId;
Map<String,Object>map=newHashMap<String,Object>();
map.put("querySql",queryAllGroup);
List<Map<String,Object>>results=indexService.getCommonQuery("getCommonQuery",map);
JSONArrayallGroupArray=JSONArray.fromObject(results);
jsonObject.put("allGroupArray",allGroupArray);
map.put("querySql",queryGroupById);
results=indexService.getCommonQuery("getCommonQuery",map);
JSONArraygroupByIdArray=JSONArray.fromObject(results);
jsonObject.put("groupByIdArray",groupByIdArray);
return"jsonObject";
}