I have a function that does some fairly extensive DOM manipulation, and I want to show a "Loading..." spinner while the function runs:
function showFoos() {
$('#spinner').show();
bigHairyDOMManipulation();
$('#spinner').hide();
}
function bigHairyDOMManipulation() {
for (var i=0; i < arrayOfFoos.length; i++){
buildFooBox(arrayOfFoos[i], i);
}
}
function buildFooBox(foo, index) {
$('#foos').append(
$('<li />').append(...)
.append(...)
...
);
}
Unfortunately, all of the append()
calls return quickly, so even though the view isn't ready, the function is done and the spinner hides.
I can't think of a good way of chaining all of those appends together into one chain, so I can't just tack the show()
on the front and the hide()
on the end.
Is there another way to force the hide()
call to wait for all the other manipulation to occur?