這裏做一個觀點我想在Backbone.js的錯誤到來而在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沒有完全加載,而這行是執行.so它不好tmpl_occupant,我可以做什麼來解決這個問題。
我沒說得對。我怎麼能傳遞一個字符串,而不是jQuery的參考?我也用我的代碼模板:_.template($(「tpl-item-list」)。html()), – jongbanaag 2012-03-23 02:39:26
opps。現在明白了。謝謝 :) – jongbanaag 2012-03-23 02:41:36