0
var $foldedView = $(e.currentTarget);
var foldedViewId = $foldedView.attr('id');
var model = this.collection.get(parseInt(foldedViewId));

I'm debugging this code and foldedViewId has a value of "151140". Now when I look up the this.collection object, I can clearly see that there is a model with an id of 151140.

enter image description here

My problem is that this.collection.get with the foldedViewId (parsed or not) returns undefined....Is there a bug in backbone?

  • Seems to work http://jsfiddle.net/nikoshr/AM6Lc/ Is there a `collection.fetch` involved somewhere? – nikoshr May 06 '14 at 13:41
  • Yes it works in 99.9% of my application, I don't know why it doesn't work there. And yes there is a fetch involved when the application boots. –  May 06 '14 at 13:53
  • Then probably an asynchronism problem http://stackoverflow.com/questions/8413500/backbone-js-populating-a-collection/8415515#8415515 – nikoshr May 06 '14 at 14:17
  • No because I'm putting a breakpoint when I'm debugging. I know the values I see are the actual values at a certain point. –  May 06 '14 at 14:21
  • The answer may be → https://stackoverflow.com/questions/10937031/collection-get-returning-undefined-in-backbone-js/33430737#33430737 – kenberkeley Oct 30 '15 at 07:31

1 Answers1

0

You can start by looking at this._byId instead of this.models and making sure your value is there.

Then make sure its not a string in _byId.

You'll have to go from there depending on what you find.

Edit.. wait.. have you checked the reference to this.collection? What object are you in? Did you forget to bindAll? If so this is a duplicate: Collection.get returning undefined in backbone.js

GeorgeFrick
  • 154
  • 2
  • 7