Test jquery templates
HTML
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
<script id="testTemplate" type="text/x-jquery-tmpl">
{{if title.length}}
<h3>${title}</h3>
<p>Detail: ${$item.objectToString("detail")}</p>
{{/if}}
</script>
<div id="bookList"></div>
JavaScript
var book = [
{ title: "Goodnight, World!",
detail: { author: "Jojo Mojo", synopsis : "What the ..." }}
];
$("#testTemplate").tmpl(book, {
objectToString : function(key) {
var detail = this.data[key];
return detail.author + " " + detail.synopsis;
}
}).appendTo("#bookList");