2013-08-29 56 views
0

渲染我有如下表中没有骨干

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); 

我还创建了一个动态表已经看到只有表格元素被创建,但表格是空的。 任何想法???

回答

2

对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);