javascriptbackbone.jsbackbone-viewsbackbone-relational

Backbone outputing empty array for collection.models?


Having a problem where if I do

apples = new Apples
apples.fetch()
console.log apples
console.log apples.models

console.log apples will out put the Apples Collection, with models: Array(10) listed inside the object.

But, console.log apples.models outputs an empty array.

Why does this happen?

Thanks in advance.


Solution

  • Are you trying to console.log the collection right after executing the fecth() method or waiting for the callback to be executed by using

    apples.on('reset', function(){ console.log(this.models);} ,this); 
    

    ?