特性
代码
function render(tpl, data){
var re = /{{([^}]+)?}}/;
var match = '';
while(match = re.exec(tpl)){
tpl = tpl.replace(match[0],data[match[1]]);
}
return tpl;
}
demo
var tpl = '/cube_xinbao_dial_result/{{action}}/{{report_type}}/{{query}}/?userId={{userId}}';
var data = {report_type:1, query: '2323', action: 'todolist',userId: '23234234'}
function render(tpl, data){
var re = /{{([^}]+)?}}/;
var match = '';
while(match = re.exec(tpl)){
tpl = tpl.replace(match[0],data[match[1]]);
}
return tpl;
}
console.log(render(tpl,data));
> /cube_xinbao_dial_result/todolist/1/2323/?userId=23234234