[jQuery] Stumped on Tables

[jQuery] Stumped on Tables


> I've tracked down my issue with using $.append() for table rows.
>
> First, jQuery is converting any string into a document node by
> creating a div and setting it's HTML. This has a side-effect of
> striping the first TR within the string in IE, and of striping
> ALL table tags in Firefox.
>
> Does anyone have a better idea?
Can you use Mike Geary's HTML functions instead? If you are using XMLHTTP,
return a JSON object instead of HTML. Crockford.com has JSON code for just
about any language you might be using. It's very nice to do this way because
you totally eliminate any presentational issues from the server-side code.
Here's an example from some code I have. It gets an array from JSON called
Rows:
Rows = [
{
Name: "Security",
Threat: "DataLoss",
Risk: "Low",
Desc: "No security issues found"
Note: null
},
{
... Etc ...
}
];
The JQuery code processes it like this:
$("#Results tbody").append(
$.map(Rows,function(row){
return $.TR(
$.TD($.IMG({src: row.Name+".jpg",
className: "CatIcon"}),row.Name),
$.TD(row.Risk),
$.TD($.P({className: row.Threat}, row.Desc),
row.Note? $.P({className: "SolutionNote"},
row.Note) : ""),
$.TD($.IMG({src:row.Threat+".jpg",
className: "ThreatIcon"}}),row.Threat)
)
}
));
I may have messed something up simplifying the example, but I hope the idea
is still there.
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/