我在 var template
中有一个 html 模板,在 var obj
中有一个对象。
我这样用 Javascript 调用我的模板。
var html = Mustache.render(template, obj, {
templateRef: "path/template"
});
如果我 console.log html
,原始模板显示完美,但部分 (templateRef) 部分根本没有呈现。
在我的模板中,我引用了这样的部分:
{{> templateRef}}
我尝试将部分放在同一级别(删除路径),包括扩展名(.mustache)等。但似乎没有任何效果。
有人知道我错过了什么吗?
最佳答案
Mustache.js 似乎不支持 specifying a partial by its path :
The object should be keyed by the name of the partial, and its value should be the partial text.
您必须检索模板的文本并将其提供给 Mustache.render()
(例如,使用 jQuery):
$.get('path/template.mustache', function (partialTemplate) {
var html = Mustache.render(template, obj, {
templateRef: partialTemplate
});
// ...
}, 'text');
关于javascript - 在 Mustache JS 中包含一个部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24190254/