标签:out template htm html val return eval exp 字符串
var template=`<ul>
<% for(var i=0;i < data.supplies.length;i++){%>
<li><%=data.supplies[i] %></li>
<%}%>
</ul>`;
function compile(template){
var evalExpr=/<%=(.+?)%>/g;
var expr=/<%([\s\S]+?)%>/g;
template=template
.replace(evalExpr,‘`); \n echo($1) \n echo(`‘)
.replace(expr,‘`); \n $1 \n echo(`‘);
template=‘echo(`‘+template+‘`);‘;
var script=`(function parse(data){
var output="";
function echo(html){
output+=html;
}
${template}
return output;
})`;
return script;
}
标签:out template htm html val return eval exp 字符串
原文地址:http://www.cnblogs.com/jinxin-school/p/6921189.html