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
1 Answer
Reset to default 10You need to return this
from render
function for chaining.
render: function(){
this.collection.forEach(this.addOne, this);
return this;
},
本文标签:
版权声明:本文标题:javascript - backbone.js - collection view giving "TypeError: Cannot read property 'el' of undefined&am 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741679415a2392076.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论