I am thinking Mike is right, and you wanted insertAfter rather than
appendTo.

> I could build a local string, then once the loop finishes,
> append the string where I need it.

Don't give up on your DOM approach yet,the performance of the [id$=]
selector may be the killer and your current approach is so much more
elegant than string slinging.

I think this is basically the same code with some stuff optimized. You
can replace the for-in loop with explicit assignments but it seemed
nice to do it that way and I also removed the id since not doing so
would create an invalid document (duplicate ids). Do you need to
use .clone(true) to preserve events? If not, take out the true arg.

function OnSucceeded(results, GPRowID)
{
        var $row = $("table[id$=gvBillingHistory] tr[id$=GPRow_" + GPRowID
+"]");
        $.each(results, function(i){
                if(i<=99){
                        // Clone template (DOM nodes) and assign id
                        var $template = $("#TemplateRowLineItem")
                                .clone(true).attr("id", "GPLi_"+GPRowID+"_"+i);
                        // Fill template, JSON name is the id
                        for ( var id in this )
                                $("#"+id, 
$template).text(this[id]).removeAttr("id");
                        // Add below the clicked row
                        $row.after($template);
                }
                else {
                        $("#TemplateRowMore").clone(true)
                                .attr("NextResultPage",++currResultPage)
                                .insertAfter($row);
                        //?? do you want to do this on every row > 100 ??
                }
        });
        $("#TemplateRowLoading").remove();
}

Reply via email to