Bruce Dou
Bruce Dou

Reputation: 4761

Backbonejs collection length always zero

I have a function in collection view:

addAll: function() {
  console.log(this.collection);
  console.log(this.collection.length);
  console.log(this.collection.models);
  this.collection.each(this.addOne);
},

Why the results are:

1.

d
_byCid: Object
_byId: Object
length: 6
models: Array[6]
__proto__: x

2. 0

3. []

we can see the this.collection have models and length = 6 in the first result

Upvotes: 2

Views: 3224

Answers (1)

fguillen
fguillen

Reputation: 38822

Beware console.log can cheat you

Upvotes: 3

Related Questions