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

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -