0

My Backbone Model is fetching data from an API as JSON

the structure is like:

 releases
     tracks
        length

Now I specifically want to the lenght of a track. How do achieve that?

I tried to do

afterRender: function(){
   this.model.get('releases.tracks.length');
   console.log(track);
}

but that didnt work, gives me 'undefined'

please help

SHT
  • 700
  • 4
  • 18
  • 39
  • 2
    This has been asked a number of times e.g. http://stackoverflow.com/questions/6351271/backbone-js-get-and-set-nested-object-attribute. To sum up you can do `this.model.get('releases').tracks.length` though in some cases you might want to consider nested models. – Dominic Aug 04 '14 at 09:38
  • Ok sorry, but this gives me `Cannot read property 'lenght' of undefined `... – SHT Aug 04 '14 at 09:43
  • 1
    this is because either tracks is undefined or not an array, or because you spelled `length` as `lenght` :) – Dominic Aug 04 '14 at 09:47

0 Answers0