var list = [{id:1, name:"czone", age:21}, {id:2, name:'czonechan', age:21}];
var template ='
$name$age
';
Implement a general method to assemble the template using initialization data.
function displayTemplate(list,template){
var result="";
for(var i=0,l=list.length;ivar temp=template;
for(var k in list[i])
{
var reg=new RegExp("\$" k,"g");
temp=temp.replace(reg,function(w){
return list[i][k] ;
})
}
result =temp;
}
return result;
}