Backbone.js 表未在主干中呈现
我创建了一个动态表,如下所示Backbone.js 表未在主干中呈现,backbone.js,backbone-views,backbone-events,Backbone.js,Backbone Views,Backbone Events,我创建了一个动态表,如下所示 app.View.FriendRequestTableView = Backbone.View.extend({ tagName: 'table', className: 'table table-hover', initialize : function(options) { this.options = options; this.render(); }, render: function() { $(this.el).emp
app.View.FriendRequestTableView = Backbone.View.extend({
tagName: 'table',
className: 'table table-hover',
initialize : function(options) {
this.options = options;
this.render();
},
render: function() {
$(this.el).empty();
this.options.collection.each(function(user){
var row = new app.View.FriendRequestRowView({model:user});
$(this.el).append(row.el);
});
return $(this.el);
}
});
我检查了一下,发现行的构造正确,但下面的行不起作用
$(this.el).append(row.el);
我还看到只创建了表元素,但表是空的。
有什么想法吗?在this.options.collections.each的迭代器函数中对“this”的引用可能是对窗口的引用,如果我没有弄错的话。创建迭代器函数可以使用的视图的显式引用应该可以解决您的问题
$(this.el).empty();
var _this = this;
this.options.collection.each(function(user){
var row = new app.View.FriendRequestRowView({model:user});
$(_this.el).append(row.el);
});
return $(this.el);