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:

  1. does mean rowview used once , disposed in renderrow()? or live on?
  2. if true, when kill view? adding listener model.destroy , invoke remove() @ view enough?
  3. if have row's markup rendered server, click #del events still captured , w/o rowview created?
  4. shouldn't 'click #del' better located in parent view, jquery can delegate , attach behavior there?
  5. does mean have 1 rowview per row? wouldn't mean _.template being compiled on every row? alternative?

  1. the reference dies, view can remain if there other references pointing it.
  2. 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
  3. an instance of rowview have instantiated event captured.
  4. this depends on behavior looking for, in example think each view has capture each own click #del event, if declare event in parent view how know wich row delete?
  5. normally declare template in view definition , assign compiled version of this.template this: template: _.template( "hello: <%= name %>" );.

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -