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;
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn