user2066880
user2066880

Reputation: 5024

Backbone collection object in console

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.

Upvotes: 0

Views: 59

Answers (1)

Vaibs_Cool
Vaibs_Cool

Reputation: 6150

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)
  }
});

Upvotes: 1

Related Questions