2016-02-03 113 views
0
[ 
    { 
     "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":"[email protected]", 
     "wholesalecontact":"8754181719", 
     "wholesaletlname":"ajin1,ajin3,ajin2", 
     "wholesaletlcontact":"1234567890,1234587452,8754181719", 
     "wholesaleaddress":"" 
    } 
] 

我有這樣的json值。 我需要得到wholesaletlname值,並使用jQuery像從選擇選項csv json值

<option>ajin1</option> 
<option>ajin3</option> 
<option>ajin2</option> 
+0

歡迎的StackOverflow!請閱讀[如何提出一個好問題](http://stackoverflow.com/help/how-to-ask)!我們希望您在提問之前將自己的努力投入到您的項目中。自己去吧,如果你有一個代碼庫可以工作,就回來吧。我們幫助解決問題,但沒有代碼交付服務! –

回答

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": "[email protected]", 
 
    "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>