我正在尝试使用NodeJS和Backbone渲染Handlebars模板。
到目前为止,在HTML文件中,我的工作完美无误:
app.MyView = Backbone.View.extend({
...
render: function() {
var template = Handlebars.compile( $("#my-template").html());
this.$el.html( template(this.model.toJSON()) );
return this;
}
...
});
查看HTML内部:
<script type="text/x-handlebars-template" id="my-template">
{{text}}
</script>
然而,如果我将这个视图放在Handlebars模板中,它就不能正常工作,因为{{text}}被NodeJS Handlebars编译器解释了。