从AJAX调用将字符串转换为字符串模板

时间:2016-12-15 01:57:29

标签: javascript ecmascript-6

从其他文件使用ES2015字符串模板的最佳方法是什么?

template.html

<div>
    <span>Hello, my name is ${name}.</span>
    <span>I'm a ${title}.</span>
</div>

main.js

let template = '';
let name = "Adam Curl"
let title = "Coder"
$.get("template.html", function(response) {
     template = response;
});
console.log(template);

希望输出......

<div>
    <span>Hello, my name is Adam Curl.</span>
    <span>I'm a Coder.</span>
</div>

0 个答案:

没有答案