Здесь я хочу сделать представление в 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, что я могу сделать, чтобы решить эту проблему?