Reputation: 178
I have a <select>
that I added with JQ ,
its loadded all options from a class (value + data) list return by $.ajax
call, and load it to a div.
My code:
varTempDiv+= '<select class="selectFromList" width="200">';
$.each(data.d, function (index) {
varTempDiv+= '<option value="' + this.value >+ '">' + this.txtName + '</option>';
});
varTempDiv+= '</select>';
$("#loadedDiv").html(varTempDiv);
It work fine at all in chrome , but in ie8 its froze to some second append to list length. The length start with 100 to 1000+ items.
How can i fix that things? Thanks!!
Upvotes: 1
Views: 268
Reputation: 193261
Try using native for
loop instead of jQuery.each
. It should give you significant performance improvement especially if you have so many items in your array. Take a look at this comparison http://jsperf.com/jquery-each-vs-for-loop/69.
Upvotes: 1
Reputation: 1645
What happens if you change
varTempDiv+= '<option value="' + this.value >+ '">' + this.txtName + '</option>';
to
varTempDiv+= '<option value="' + this.value + '">' + this.txtName + '</option>';
Thousand items in a select also seems unusable, maybe you should consider a different design.
Upvotes: 0