I want my view to appear when it is first created, so I call this.render(); in the initialize: function, for example, (remote code):
var MyView = Backbone.View.extend({ el: $("#mydiv"), initialize: function() { this.render(); } ...
In the render: function render: I then iterate over the child collection and add the rendered views of each child:
render: function() { this.model.somecollection.forEach(function(c) { var view = new ChildView({ model: c }); this.el.append(view.render().el);
The problem I ran into is that the link to this in the rendering function (marked with asterisks) is set to window , not to the MyView object and causes an error.
I assume that I am this.render(); render incorrectly (currently this.render(); ). How should I do this to maintain this context?
source share