【发布时间】:2015-09-25 15:54:10
【问题描述】:
好吧,
我正在使用 RequireJs 文本插件在我的主干应用程序中引入下划线模板 (.html)。不幸的是,我的模板中的下划线代码被呈现为纯文本。
define(['Backbone', 'text!Templates/BlogIndex.html', 'text!Templates/Elements/Blog/List.html'], function(Backbone, Template, ElementList){
var BlogPostIndexView = Backbone.View.extend({
initialize: function () {
this.template = _.template($(Template).html(), {posts : this.collection});
this.render();
},
render: function (Template) {
this.$el.html(this.template);
return this;
}
});
return BlogPostIndexView;
});
这是我的视图代码,你可以看到我正在拉入两个模板并设置它们。但是它被渲染为...
Globall Coach Blog Posts
<% _.each(posts, function(post){ %>
<%= _.escape(post.title) %>
<% }); %>
有人遇到过这个问题吗?
【问题讨论】:
-
text!...没有给你文字,所以你只需要说_.template(Template)?从 Underscore 1.7.0 开始,_.template(tmpl, date)不起作用,您现在需要t = _.template(tmpl); h = t(data)。 -
谢谢,看来我已经到了某个地方,伙计
标签: backbone.js requirejs underscore.js requirejs-text