jquery - Why is this list being duplicated when parsing JSON? -
i have json file i'm using populate select list. each of entries in json file being duplicated in select list. wrong, seems should work:
$.each(data, function(index, item){ items.push('<option value="'+item.partnerid +'">'+item.pname+'</option>'); $('#platform').append( items.join('') ); });
you're joining , append generated list inside loop, after each item added it.
that means every item, you're building list , appending select current item you're iterating over. given inputs [a, b, c, d]
, you'll wind [a, ab, abc, abcd]
.
you need move final join outside loop, you're appending <option>
s <select>
once after they've been built.
$.each(data, function(index, item){ items.push('<option value="'+item.partnerid +'">'+item.pname+'</option>'); }); $('#platform').append( items.join('') );
Comments
Post a Comment