I posted a question yesterday dealing with parsing json data. In one of the follow up answers someone said I was taking a performance hit by using the jQuery append() function within each iteration, while using each().
I was doing:
$.getJSON("http://myurl.com/json?callback=?",
function(data) {
// loop through each post
$.each(data.posts, function(i,posts){
... parsing ...
// append
$('ul').append('<li>...</li>');
});
});
I modified it to be this:
$.getJSON("http://myurl.com/json?callback=?",
function(data) {
// create array
arrPosts = new Array();
// loop through each post
$.each(data.posts, function(i,posts){
... parsing ...
arrPosts[i] = '<li> ... </li>';
});
// output
for (i=0;i<arrPosts.length;i++){
$('ul').append(arrPosts[i]);
}
});
And this seems to be working properly, example demo: http://jsbin.com/isuro
But am I doing this right? I'm somewhat of a noob and just want to make sure I'm approaching this correctly. Thanks for any advice!