backbone.js - 收集视图给出"TypeError:无法读取未定义的属性'el'错误

fla*_*unk 2 javascript jquery backbone.js

我在这里设置了一个问题的jsBin:http://jsbin.com/oSIJunu/2/edit?html,js,console,output

由于渲染函数(friendView.render().el)上el属性的问题,Collection视图无法渲染.

该视图如下所示:

var FriendListView = Backbone.View.extend({
    render: function(){
        this.collection.forEach(this.addOne, this);
    },
    addOne: function(friendModel){
        var friendView = new FriendView({model: friendModel});
        this.$el.append(friendView.render().el);
    }
});
Run Code Online (Sandbox Code Playgroud)

26p*_*h19 8

你需要thisrender链接功能返回.

    render: function(){
        this.collection.forEach(this.addOne, this);
            return this;
    },
Run Code Online (Sandbox Code Playgroud)