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('') ); }); 

fiddle

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

Popular posts from this blog

c# - ItextSharp font color issue in ver 5.5.4+ -

jquery - Multiple issues with pushstate: history, loading, calling functions -

ios - retrievePeripherals deprecated in IOS7 how to substitude it with retrievePeripheralsWithIdentifiers -