Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 表未在主干中呈现_Backbone.js_Backbone Views_Backbone Events - Fatal编程技术网

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