I have read the post here about using setTimeout() during intensive DOM processing (using JavaScript), but how can I integrate this function with the below code? The below c
It just so happens that I was posting about this a moment ago here. Here is a timed loop function:
function processLoop( actionFunc, numTimes, doneFunc ) {
var i = 0;
var f = function () {
if (i < numTimes) {
actionFunc( i++ ); // closure on i
setTimeout( f, 10 )
}
else if (doneFunc) {
doneFunc();
}
};
f();
}
For your situation this would be used like this:
function appendToSelect () {
$("#mySelect").children().remove() ;
$("#mySelect").html(
''
);
var j = 1 ;
processLoop(function (i){
$("#mySelect").append(
''
);
}, obj.data.length);
}
You'll want to make sure that you have a closure or some other access to the obj variable within the iteration function.
Hope this helps.