0
我有一個骨幹集合,我已經像這樣初始化:取不更新collection.model.models
myCollection = new MyCollection([], {type: 'animals', params: {username: 'steve'}});
myCollection.fetch();
console.log(myCollection) // prints out an object that includes 'models' and the newly fetched models
console.log(myCollection.models) // prints out an empty list []
沒有人知道爲什麼嗎?
那麼你的收藏功能是什麼樣子?另外,你爲什麼傳入一個空數組? – Austin 2012-07-09 15:30:40
可能是一個異步問題。類似於http://stackoverflow.com/questions/9584870/backbone-js-fetch-not-actually-setting-attributes/9585427#9585427 – nikoshr 2012-07-09 15:32:14
fetch是一個異步操作,因此無論您在獲取後立即執行操作,最有可能在執行抓取完成,導致相當隨機的結果。將控制檯日誌記錄到'fetch'的'success'-函數中,看看會發生什麼 – jakee 2012-07-09 15:33:18