2013-08-25 45 views
2

我已经在这里设立问题的jsBin:http://jsbin.com/oSIJunu/2/edit?html,js,console,outputBackbone.js的 - 集合视图使“类型错误:无法读取属性未定义的“厄尔尼诺”错误

集合视图不会因渲染到问题与渲染功能(friendView.render()。el)el属性)。

的看法是这样的:

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

渲染方法不返回任何值 –

+0

我不知道骨干......但也有一些是严重错误在这里......因为递归调用 –

+0

您需要返回您FriendView对象'FriendView的.render()'允许可连续调用。 '回到这个;'应该这样做。 –

回答

8

你需要从render函数返回this的链接。

render: function(){ 
     this.collection.forEach(this.addOne, this); 
      return this; 
    }, 
相关问题