2
我有這樣的代碼在我的骨幹應用:在我的Collection上調用fetch會實例化它在Backbone中接收到的所有模型嗎?
app.Collections.quotes = new app.Collections.Quotes();
app.Collections.quotes.fetch();
我能看到的對象的數組中的網絡選項卡返回,但是當我向外膨脹的集合,該機型陣列內爲0。難道他們實例化作爲fetch()在新的Collection上運行時的模型?
這是我收集:
app.Collections.Quotes = Backbone.Collection.extend({
model: app.Models.Quote,
url: function() {
return app.Settings.apiUrl() + '/quotes';
}
});
編輯:
app.Collections.quotes.fetch({
success: function(){
app.Utils.ViewManager.swap('section', new app.Views.section({section: 'quotes'}));
}
});
而且在我的模型:
idAttribute: 'Number',
這是修復!感謝幫助。 Dan kinda在評論中指出了我正確的方向......
'fetch'應該創建新的模型實例...你有來自網絡選項卡的數據,也許有一些模型代碼? –
@Matt如果返回的對象沒有'id'鍵,我猜集合Fetch()不能將它們實例化爲Models? – benhowdle89
我假設你只是在提取後立即控制檯日誌...等待收集重置事件,然後檢查它 – jakee