【发布时间】:2013-01-27 09:09:28
【问题描述】:
我正在尝试使用backbone.js 开发一个简单的RSS 应用程序。我正在使用这个backbone.js tutorial。定义模板时,我在第 2 行(模板)上收到以下错误。 有人能告诉我为什么教程中定义了 tagName: "li" 吗?
未捕获的类型错误:无法调用未定义的方法“替换” 主干.js
JavaScript
window.SourceListView = Backbone.View.extend({
tagName:"li",
template: _.template($('#tmpl_sourcelist').html()),
initialize:function () {
this.model.bind("change", this.render, this);
this.model.bind("destroy", this.close, this);
},
render:function (eventName) {
$(this.$el).html(this.template(this.model.toJSON()));
return this;
},
close:function () {
$(this.el).unbind();
$(this.el).remove();
}
});
HTML
<script type="text/template" id="tmpl_sourcelist">
<div id="source">
<a href='#Source/<%=id%>'<%=name%></a>
</div>
</script>
谢谢
【问题讨论】:
-
尝试在没有数据的情况下运行模板,看看你会得到什么...this.$el.html(this.template())
-
它在第 2 行出错(模板:_.template($('#tmpl_sourcelist').html()),)。不知道你推荐什么。
标签: javascript html templates backbone.js underscore.js