//模板渲染 json //str:"<div>{{name}}</div><div>{{age}}</div><div>{{grade}}</div>" //data:{name:"孙立",age:55,grade:33}; function drawing(str,data){ var drawed=str.replace(/{{(w+)}}/g,function(a,b){ return data[b]; }) return drawed; } //模板渲染 包含json对象的数组 //str:"<div>{{name}}</div><div>{{age}}</div><div>{{grade}}</div>" //data:[{name:"孙立",age:55,grade:33},{name:"孙立1",age:55,grade:33},{name:"孙立2",age:55,grade:33}]; function drawingArray(str,data){ var result=""; for(var i=0;i<data.length;i++){ result+=drawing(str,data[i]); } return result; }