fetch是异步的,如果立即调用,则不会填充您的集合
render。要解决此问题,您只需将集合 重置 事件(Backbone的 同步 事件>
= 1.0)绑定到视图render:
theView = Backbone.View.extend({ el: $("#temp"), initialize: function () { this.collection = new theCollection(); // for Backbone < 1.0 this.collection.on("reset", this.render, this); // for Backbone >= 1.0 this.collection.on("sync", this.render, this); this.collection.fetch(); }, render : function () { console.log( this.collection.toJSON() ); }});请注意bind方法的第三个参数,为该方法提供正确的上下文:http : //documentcloud.github.com/backbone/#FAQ-
this



