Tuesday, October 12, 2010

jQuery.appendTemplate(url, args[])

Appends a template from file onto an element.

url: template url
args[]: dynamic list of arguments that goes into the template

Example code:



$(document).ready(function(){
$.getJSON(
"data/data.json",
function(data){

$.each(data, function(i, item){
$("#myList").appendTemplate(
"templates/row.template",
item.url,
item.text);
});

});
});

So what does it do?

The appendTemplate function loads a template from file and fills it with the arguments you pass. Sort of like a string.format(args[]) function.

Author

Written by Anders Nygaard. Fan or hate mail: anders.nygaard at googles mail service



Download

No comments: