Ajax獲取Json對象綁定下拉框


Html 部分:

<html>
<head></head>
<body>
<div class="form-group">
                <div class="col-sm-3">
                    <label class="control-label">集團:</label>
                </div>
                <div class="col-sm-9">
                    <select id="groupType" name="offsetType" class="table ">
                    </select>
                </div>
 </div>
</body>
</html>

 

Js部分:

$.ajax({
   type: "post",
   contentType: "application/x-www-form-urlencoded;charset=utf-8",
   url: rootPath + '/group/getGroupList.json',
   dataType: "json",
   data: "",
   success: function (response) {
      if (response.code == "0") {
         var ddl = $("#groupType");//列表框id
          //方法1:添加默認節點
         ddl.append("<option value='-1'>--請選擇--</option>");
         //轉成Json對象
         var result = eval(response.obj);
         //循環遍歷 下拉框綁定
         $(result).each(function (key) {
         //第一種方法
         var opt = $("<option></option>").text(result[key].organizationName).val(result[key].organizationCode);
         ddl.append(opt);
         });
      } else {
         layer.msg('加載集團失敗');
      }
   },
   error: function () {
      layer.msg('error');
   }
});

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM