下面的代码 (*) 有效,但我不想使用:
$(this.el).html(Mustache.render("<h2>{{title}}</h2>", view));
我想做的事:
$(this.el).html(Mustache.render("somePath/myFile.html", view));
我该怎么做?
(*)
render: function ()
{
var view = {
response: this.model.title
};
$(this.el).html(Mustache.render("<h2>{{{title}}}</h2>", view)); // it works
$(this.el).html(Mustache.render("myFile.html", view)); // it does not work
},
最佳答案
你可以这样做:
$.get("myFile.html", function(html) { $(this.el).html(Mustache.render(html, view)) });
$.get
是文件的简写 AJAX 请求,然后使用文件的内容 (html
) 作为 Mustache 呈现的 HTML。
关于javascript - mustache 模板 : how to refer to external file in backbone view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10516703/