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:
- does that mean
rowView
is only used once and disposed inrenderRow()
? Or does it live on? - if true, when to kill the View? is adding listener to
model.destroy
and invokeremove()
at the view good enough? - If I already have the row's markup rendered from the server, would the
click #del
events still get captured and do something w/o arowView
created? - shouldn't
'click #del'
be better located in the parent view, so that jQuery can delegate and attach behavior there? - does that mean I have 1 rowView per row? wouldn't that mean the _.template is being compiled on every row? any alternative?