ajax 成功後動態加載 check 是否選中

後臺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;">&nbsp;${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>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章