//collection に変化があったら、render呼び出し
<code>this.listenTo(this.collections, 'all', this.render );</code>
//fetchでデータ取得
this.collections.fetch({silent: true});
//renderする
render: function () { console.log(this.collections.get('item').length); }
とした時、fetch() の先で、ajax なりでデータをサーバーから取得するタイミングによって、item自体がなかったりするので、
render: function () { if(this.collections.has('item')){ //あるかどうかチェック console.log(this.collections.get('item').length); } }
とするか、
this.model.fetch({ success: this.render // $.ajax 'success' callback });
とするか。後者は、ちょっと意味が違う。
そういうのがもろもろ書かれている。
http://chilipepperdesign.com/2013/01/15/backbone-js-bind-callback-to-successful-model-fetch/