我很難用我從API提取的集合初始化簡單視圖。當我嘗試從視圖中返回集合時,我嘗試的所有內容都返回一個空數組。視圖中的骨幹集合初始化
app.models.Employee = Backbone.Model.extend({
});
app.collections.Employees = Backbone.Collection.extend({
Model: app.models.Employee,
url: "http://api.sample.com",
initialize: function(){
this.fetch();
},
parse: function(response){
console.log(response)
},
});
app.views.Container = Backbone.View.extend({
el: $('.container'),
initialize: function(){
this.collection = new app.collections.Employees();
console.log(this.collection)
var that = this;
this.collection.fetch({
success: function(){
that.render();
}
});
},
render: function(){
console.log(this.collection) //returns no models
}
});
所以......它看起來像您可能通過將該console.log解析來阻止解析數據?嘗試刪除完全不必要的重寫解析方法? – billjamesdev
而且你確實意識到你要調用兩次,對不對? – billjamesdev