Allan Raquin
Allan Raquin

Reputation: 613

Backbone - Collection not populating from JSON

I'm trying to populate a Backbone collection from the JSON that spotify API return me. However, after I try populating the collection I'm getting this with a console.log() : playlistSpotify child {length: 1, models: Array[1], _byId: Object}. But my collection should contain 3 objects (3 objects in the JSON returned).

Any ideas of what's going on?

JS:

After some exploration I see this thing when I console.log the collection. I can't really understand what's happened.

Any help would be appreciated ! :)

Upvotes: 0

Views: 61

Answers (1)

MysterX
MysterX

Reputation: 2368

You have a wrong creation of the instances. Change it to the next:

var playlistCollection = new Playlists2(response.items);
var playlistView = new PlaylistSpotifyView({ model : playlistCollection });

To initialize collection, you need just simply pass an array of objects as the argument to the constructor of collection

Upvotes: 1

Related Questions