0

I'm logging one of my Backbone collections, and I'm getting this output. In the object summary why does it say that the length is 0 and the models array is empty, but in the dropdown detail, gives the correct length and model array? Also when I run console.log(this.collection.models) it returns an empty array just like in the summary.

user2066880
  • 4,825
  • 9
  • 38
  • 64

1 Answers1

1

It might be a race condition since fetch is an asynchronous method.

Have you confirmed fetch has processed the request from the server before you call this.model.itemList?

To confirm this, add a console log message in the fetch method

user.fetch({
  success: function(response){
    user.itemlist = new itemlistcollection(response.items)
    console.log(user.itemList)
  }
});
Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61