「ビューはテンプレートに依存しない」というあなたの仮定と矛盾する解決策を提供します。
render()
モデルで何かが変更されたときに電話をかけると、特にテンプレートが大きい場合は、ブラウザでこれが点滅します。
私の推奨事項はrender
、ビューが初めて視覚化されたときに1回だけ発生するupdate
ビューと、具体的なモデル属性にリンクされたビューの小さな部分の更新を担当するいくつかのヘルパーメソッドを分離することです。
例えば:
// code simplified and not tested
var MyView = Backbone.View.extend({
initialize: function(){
this.model.on( "change:title", this.updateTitle, this );
this.model.on( "change:description", this.updateDescription, this );
// ... more change:XXX
},
render: function(){
this.$el.html( this.template( this.model.toJSON() ) );
},
updateTitle: function(){
this.$el.find( ".title" ).html( this.model.get( "title" ) );
},
updateDescription: function(){
this.$el.find( ".description" ).html( this.model.get( "description" ) );
},
// ... more updateXXX()
})