how to very slow to load large list of options in SELECT element maker.
Marker Option list.
var html = "";
while(loop)
{
html += "<option value='"+list[i] + i+"'>"+list[i]+"</option>";
}
$(numberList).html(html);
issue :http://stackoverflow.com/questions/9639703/ie8-javascript-very-slow-to-load-large-list-of-options-in-select-element
Marker Option list.
var html = "";
while(loop)
{
html += "<option value='"+list[i] + i+"'>"+list[i]+"</option>";
}
$(numberList).html(html);
My guess is that that particular DOM operation is just really slow in IE8. In general, manipulating the DOM is the slowest type of operation in any browser. To get around that I typically try to find ways to combine my changes into one DOM update (e.g. add an HTML "batch" of 6000 rows to a table instead of individually adding 6000 rows to a table).
In this example the only way to do that would probably be to create all of the
<option>
elements as HTML and then use innerHTML
to insert them into the <select>
. See this jsfiddle example:http://jsfiddle.net/pseudosavant/bVAFF/
I don't have IE8 to test with, but it is much faster even in Firefox (22ms vs 500ms) for me.
Update
Looks like it didn't work with
innerHTML
in IE for loading the list, but it did work for clearing it. Loading it works using jQuery $(o).html(html);
though. I updated the jsfiddle example and it works in IE9, and hopefully IE8 now.Javascript:
$(document).ready(function(){
loadListBatch();
});
function loadListBatch() {
clearListBatch();
var start = new Date().getTime();
var o = document.getElementById("listLookupAvailableItems")
var html = "";
for (var i = 0; i < 6000; i++) {
html += "<option value='"+'XYZ' + i+"'>"+'XYZ ' + i+"</option>";
}
// o.innerHTML = html; // Only one DOM operation, but still doesn't work in IE
$(o).html(html); // Using jQuery to insert the HTML makes it work with IE
console.log('Load time: ' + (new Date().getTime() - start));
}
function clearListBatch() {
var start = new Date().getTime();
document.getElementById("listLookupAvailableItems").innerHTML = ""; // It was already only one DOM call, but this is faster it seems.
console.log('Clear time: ' + (new Date().getTime() - start));
return false;
}
issue :http://stackoverflow.com/questions/9639703/ie8-javascript-very-slow-to-load-large-list-of-options-in-select-element
댓글 없음:
댓글 쓰기