我在互联网上搜索过,但我找不到javascript或jquery的正确语法;最后如果可能的话;要做的例如->
. js
array = {title: 'hihihi',
Name: 'hahaha',};
array.forEach((array) => { var template = load('test.html')});
$("#ok").html(template);
test.html
<div id="test">${array.title}</div>
index . html
<div id="ok"></div>
是否有可能这样做?
下面是我找到的解决方案:
. js
async function writeTemp(arg) {
var template = "";
template = await (await fetch('test.html')).text();
template = eval("`" + template + "`");
Object.keys(arg).forEach(prez => {
template;
});
$("#ok").html(template);
}
writeTemp(array);
test.html
<div id="test">${arg.title}</div>
index . html
<div id="ok"></div>
提前感谢。
我知道eval不是很受欢迎,但这似乎是你问题的唯一解决方案。
var array = {
title: 'hihihi',
Name: 'hahaha',
};
var template = load('test.html')
template = eval("`" + template + "`");
$("#ok").html(template);