来自select选项的csv json值

时间:2016-02-03 10:22:32

标签: jquery json csv

[  
   {  
      "outletid":6117,
      "wholesaleid":3,
      "outletuniid":"OLT1006117",
      "outletname":"new outlet",
      "outletaddressone":"address one",
      "outletaddresstwo":"address two",
      "outletlandmark":"Landmark new",
      "outletemail":null,
      "outletcontactperson":"Ajin",
      "outletcontact":"9787132227",
      "itcassert":"qwertyui",
      "status":0,
      "createdDate":"2016-02-01 17:34:24",
      "wholesalecode":"WSH1003",
      "wholesalename":"Whoshop new",
      "wholesaleemail":"who@gmail.com",
      "wholesalecontact":"8754181719",
      "wholesaletlname":"ajin1,ajin3,ajin2",
      "wholesaletlcontact":"1234567890,1234587452,8754181719",
      "wholesaleaddress":""
   }
]

我有像这样的json值。 我需要获取wholesaletlname值并使用类似

的jquery将其放在select选项值中
<option>ajin1</option>
<option>ajin3</option>
<option>ajin2</option>

1 个答案:

答案 0 :(得分:0)

您已使用split()

var json = [{
  "outletid": 6117,
  "wholesaleid": 3,
  "outletuniid": "OLT1006117",
  "outletname": "new outlet",
  "outletaddressone": "address one",
  "outletaddresstwo": "address two",
  "outletlandmark": "Landmark new",
  "outletemail": null,
  "outletcontactperson": "Ajin",
  "outletcontact": "9787132227",
  "itcassert": "qwertyui",
  "status": 0,
  "createdDate": "2016-02-01 17:34:24",
  "wholesalecode": "WSH1003",
  "wholesalename": "Whoshop new",
  "wholesaleemail": "who@gmail.com",
  "wholesalecontact": "8754181719",
  "wholesaletlname": "ajin1,ajin3,ajin2",
  "wholesaletlcontact": "1234567890,1234587452,8754181719",
  "wholesaleaddress": ""
}]

var arr = json[0].wholesaletlname.split(',');

$(arr).each(function(i, item) {
  $("#ddl").append("<option>" + item + "</option>");
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<select id="ddl">
</select>