Parse JSON Array File and Populate The Result Into Select -
i'm doing android phonegap project in company. have json file , want html select box. still newbie, haven't understand json parsing mostly.
here's json file (city.json) :
[{"cityid":1,"cityname":"magelang"},{"cityid":2,"cityname":"jayapura"},{"cityid":3,"cityname":"aceh"}]
i didn't know whether it's needed parsed or not. have followed rayell answer in thread. jquery getjson populate select menu question
so, code these populate result option in select box.
$.getjson('city.json', function(data){ var html = ''; var len = data.length; (var = 0; i< len; i++) { html += '<option value="' + data[i].cityid + '">' + data[i].cityname + '</option>'; } $('#city').append(html); });
but didn't worked on code. select box has none options :( solutions? before.
your for
loop won't work on objects. arrays.
you need use for (var in data) {
loop through properties of object.
Comments
Post a Comment