【发布时间】:2011-05-16 12:08:59
【问题描述】:
这里我想在backbone.js中做一个视图
// The DOM element for a User item...
var UserView = Backbone.View.extend({
//... is a list tag.
tagName: "li",
// Cache the template function for a single item.
template: _.template($('#tmpl_occupant').html()),
// a one-to-one correspondence between a **User** and a **UserView** in this
// app, we set a direct reference on the model for convenience.
initialize: function() {
_.bindAll(this, 'render', 'close');
this.model.bind('change', this.render);
this.model.view = this;
},
// Re-render the contents of the User item.
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
}
});
我把这个视图代码放在 user.js 中,当 index.html 加载它时,它会被调用并给出错误
str is null
http://myserver/rahul/js/underscore-1.1.3.js
Line 675
我认为这是因为删除此行时没有出现错误
template: _.template($('#tmpl_occupant').html()),
<script type="text/html" id="tmpl_occupant">
<%=user.username%> is in <%=gib.name%> (<%=channel%>)
</script>
我认为这是因为执行此行时 index.html 没有完全加载。所以它不适合 tmpl_occupant ,我该怎么做才能解决这个问题。
【问题讨论】:
标签: jquery templates backbone.js