backbone.js - When should I not use a self-rendering view? -
i've been studying this backbone tutorial , came across bit of code:
var libraryview = backbone.view.extend({ el:$("#books"), initialize:function(){ this.collection = new library(books); this.render(); }, ... }); the author explains this.render() makes view render when constructor called.
when not want view self-render?
the render method nothing more adding html dom using jquery's html or append methods. choose call render method on view architectural choice.
backbone said apply mv* pattern models bound directly view.
such, view render upon instantiation, , have ability render when model changes.
however, backbone leave lot of decisions developer , flexible library. there nothing technically prevents use control objects manage flow of views; such, object can instantiate , re-render view well.
var view = new bb_view(); view.render(); in end, render method on view, , can define own methods well. example reason why call custom methods on view outside view, when keep reference array of views.
event occurs, loop through views, might add conditions, , call custom method on particular views based on condition.
Comments
Post a Comment