后台json 数据回传
Map<String, List> mapUtils = new HashMap<String, List>();
mapUtils.put("staffGroupDetailList", staffGroupDetailList);
JSONObject object = JSONObject.fromObject(mapUtils);
result = object.toString();
outPutMssage(result);
前台js
动态加载 check 是否选中
function selectManager(){
var managerId =$("#managerId").val();$.ajax({
async:false,
type: 'POST',
url: '${pageContext.request.contextPath}/setting/selectManagerChange.action?t"=' +Math.random(),
data: {"managerId":managerId},
dataType: 'json',
success:function(data){
if(data!= null && data !=-1){
var groupList = data.staffGroupDetailList;
var cbeGroup = 'cbxGroup';
var staffGroup = '';
$("input[name='selectValue']").each(function(index) {
cbeGroup= 'cbxGroup' + index;
$("#"+cbeGroup).attr("checked",false);
});
var index =0;
for(index = 0;index <groupList.length;index++){
staffGroup =groupList[index];
if(staffGroup.staff_id !='' && staffGroup.s_g_id == (index+1)){
cbeGroup= 'cbxGroup' + index;
$("#"+cbeGroup).attr("checked",'checked');
}
}
}
}
});
}
页面代码
<s:iterator value="StaffGroupDetailList" status="record">
<tr id = "selectList">
<td style="width: 130px;"> ${s_g_name}</td>
<td> <input id="cbxGroup<s:property value="#record.index"/>" name="selectValue" id="displayBox" style="width: 20px; vertical-align:-5px;" type="checkbox" ${(staff_id!=null)?'checked': ''} value="<s:property value="s_g_id"/>""> </td>
</tr>
</s:iterator>