Open qappleh opened 3 years ago
示例:
const template = '嗨,{{ info.name.value }}您好,今天是星期 {{ day.value }}'; const data = { info: { name: { value: '张三' } }, day: { value: '三' } }; render(template, data); // 嗨,张三您好,今天是星期三
function render(template, data) { return template.replace(/\{\{([\s\S]+?)\}\}/g, function(match, $1) { var val = $1.trim(); return eval('data.' + val) }) }
示例: