Life cycle of a backbone.js view, a few beginner questions -
can please explain, life cycle of view (controller), say, row in todo list app?
app.rowview = backbone.view.extend({ events:{ "click #del" : "delrow" } }); most of tutorials, appview 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 mean
rowviewused once , disposed inrenderrow()? or live on? - if true, when kill view? adding listener
model.destroy, invokeremove()@ view enough? - if have row's markup rendered server,
click #delevents still captured , w/orowviewcreated? - shouldn't
'click #del'better located in parent view, jquery can delegate , attach behavior there? - does mean have 1 rowview per row? wouldn't mean _.template being compiled on every row? alternative?
- the reference dies, view can remain if there other references pointing it.
- you kill view when not needed more, when not visible more. if view binding event have unbinding them before call
remove(): pattern manage views in backbone - an instance of
rowviewhave instantiated event captured. - this depends on behavior looking for, in example think each view has capture each own
click #delevent, if declare event in parent view how know wich row delete? - normally declare template in view definition , assign compiled version of
this.templatethis:template: _.template( "hello: <%= name %>" );.
Comments
Post a Comment