当我创建一个新集合、获取响应并覆盖解析时,我看到集合中记录了模型数组,但在获取返回后我无法访问它。是因为我没有在fetch
方法中正确指定一些东西吗?
class MyCollection extends Backbone.Collection
model: MyModel
fetch: () ->
$.ajax
type: 'GET'
url: '/customurl'
success: (data) =>
@parse data
parse: (resp) ->
if !resp
return []
things = []
# parse that shit and things.push new MyModel()
console.log 'things: ' + JSON.stringify things # this logs correctly
things
window.myCollection = new MyCollection()
window.myCollection.fetch()
# wait some time, see it logged inside collection parse method...
console.log JSON.stringify window.myCollection # logs as []