您看不到模型的最大原因是因为渲染正在异步之前发生 fetch
已经完成。
下面的事情会更好:
mdm.LinksView = Backbone.View.extend({
el: '#link_list',
initialize: function() {
this.collection = new mdm.Posts();
this.listenTo(this.collection, 'reset', this.render);
this.collection.fetch({reset: true});
}
以上代码为侦听器设置了 reset
事件 collection
并执行 render
发生这种情况时的功能。
另外,你可以经过 success
和 error
处理者进入 fetch
并手动调用渲染函数。
this.collection.fetch({
success: _.bind(function() {
this.render(); }, this)
});
希望这可以帮助!