Reputation: 32915
Can someone please explain, what is the life cycle of a View (controller), say, for a Row in a TODO list app?
App.RowView = Backbone.View.extend({
events:{
"click #del" : "delRow"
}
});
Most of the tutorials, the AppView would do this:
render: function()
{
this.collection.each(this.renderRow, this);
return this;
},
renderRow: function(row)
{
var rowView = new App.RowView({model:element});
this.$('#rows').append(rowView.render().el);
}
Questions:
rowView
is only used once and disposed in renderRow()
? Or does it live on?model.destroy
and invoke remove()
at the view good enough?click #del
events still get captured and do something w/o a rowView
created?'click #del'
be better located in the parent view, so that jQuery can delegate and attach behavior there? Upvotes: 1
Views: 2375
Reputation: 38888
remove()
: Pattern to manage views in backboneRowView
have to be instantiated for the event to be captured.click #del
event, if you declare the event in the parent View how do you know wich row to delete?this.template
like this: template: _.template( "hello: <%= name %>" );
. Upvotes: 2