3
如何将编译的下划线模板追加到JS文档片段?将编译的下划线模板附加到文档片段
var obj = {first: "Joel", last: "Spolsky"},
frag = document.createDocumentFragment(),
tmpl = $('#template').html(),
compiled = _.template(tmpl, obj);
frag.appendChild(compiled);
当我console.log(frag)
,我得到这个错误:
`Failed to execute 'appendChild' on 'Node': The new child element is null.`
我已经确认compiled
包含分析模板字符串;是否有另一个步骤,我错过了使编译的模板可用于文档片段?
“编译”通常不表示评估的模板,而是一个被编译的函数。 – Bergi