Hi Josh and all
Many thanks for the useful tips. I appreciate it a lot.
As for Maruicio's question...Looks like you solved it. The link works
fine in FF.
Yes! I've solved it with a different aproach. I'll try yours ASAP.
-------------------------------------------------------------
3) instead of obj['name'] use obj.name
Done! Tks.
-------------------------------------------------------------
As I get rid of the ('#insert_here').empty(); in order to do my solution
work
now I need disable the 2nd and next clicks on the "show" button.
I tried unbind() method in a callback function like so:
$('#go').click(function() {
// the request code
}, function() {
$('#go').unbind('click');
});
But this didn't works!
Any help will be welcome
Regards
Maurício
-----Mensagem Original-----
De: "Josh Powell" <seas...@gmail.com>
Para: "jQuery (English)" <jquery-en@googlegroups.com>
Enviada em: sábado, 21 de março de 2009 17:16
Assunto: [jQuery] Re: getJSON() response into a table
$.getJSON("url", function(json){
$(json).each(function(){
row = $("#table").append("<tr>");
$(row).append("<td>").html(json.cell1.value);
$(row).append("<td>").html(json.cell2.value);
});
});
something like this?
This is a very, very, very... very slow way to append
var html = '<tbody>'
$(json).each(function(){
html += '<tr><td>' + json.cell1.value + '</td><td>' +
json.cell2.value + '</td></tr>';
});
html += '</tbody>';
$('#table').append(html);
Is about 20 times faster.
You can bump it up another couple of times faster by sticking all of
the strings in an array and using .join before inserting them in the
html, but you lose so much legibility of code that I only do that when
doing thousands of string concatenations on large strings.
As for Maruicio's question...Looks like you solved it. The link works
fine in FF.
A few other tips about the code:
1) do the .append outside of the loop by using the loop to create one
long string for about 10x speed increase.
2) stick the one long string into one DOM node like a tbody for about
a 6x speed increase.
3) instead of obj['name'] use obj.name They both work, but the first
makes it look like a hash when you are really using properties of an
object.
Cheers,
Josh Powell