admin管理员组

文章数量:1302869

i've set up a jsBin of the issue here: ,js,console,output

The Collection view isn't rendering due to an issue with the el property on the render function (friendView.render().el).

The view looks like this:

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

i've set up a jsBin of the issue here: http://jsbin./oSIJunu/2/edit?html,js,console,output

The Collection view isn't rendering due to an issue with the el property on the render function (friendView.render().el).

The view looks like this:

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);
    }
});
Share asked Aug 25, 2013 at 15:27 flashpunkflashpunk 7722 gold badges13 silver badges38 bronze badges 3
  • 5 the render method is not returning any value – Arun P Johny Commented Aug 25, 2013 at 15:28
  • I don't know backbone... but there is something seriously wrong here... because of the recursive calls – Arun P Johny Commented Aug 25, 2013 at 15:30
  • You need to return your FriendView object in FriendView.render() to allow for chainable calls. return this; should do it. – Will M Commented Aug 25, 2013 at 15:33
Add a ment  | 

1 Answer 1

Reset to default 10

You need to return this from render function for chaining.

    render: function(){
        this.collection.forEach(this.addOne, this);
            return this;
    },

本文标签: