javascript - Access to nested object json in SoundCloud with ember-data -
i working on soundcloud json favorites songs user.
you can see here

i can access favorites tracks can not access user id , username.
here code using returns favorite properties , have commented code not working return user properties.
i error in console "uncaught typeerror: item.user.foreach not function"
what doing wrong? right way access user properties?
model: function(params) { var artist, favoritelistproxy, self; self = this; artist = params.artist; this.controllerfor('application').set('artistname', artist); favoritelistproxy = ember.arrayproxy.create({ content: [] }); return new ember.rsvp.promise(function(resolve, reject) { return sc.get("/users/" + 'mannaio' + "/favorites", {limit: 40}, function(favorites) { if (favorites.length) { favorites.foreach(function(item, index, arr){ var favorite; favorite = self.createfavoritelist(item, favoritelistproxy); // return item.user.foreach(function(user, index, arr){ // return user = self.createuser(user, favorite); // }); }); favorites = favoritelistproxy.get('content') return resolve(favorites); } }); }); }, createfavoritelist: function(favorite, arr) { var record; record = this.store.createrecord('favorite', {}); record.setproperties({ id: favorite.id, title: favorite.title, artwork_url: favorite.artwork_url, genre: favorite.genre }); arr.pushobject(record); return record; }, // createuser: function(user, favorite) { // var record; // record = this.store.createrecord('user', {}); // record.setproperties(user).set('favorite', favorite); // return record; // },
it appears me item.user object , not array. therefore doesn't have foreach method.
so try:
return self.createuser(item.user, favorite);
Comments
Post a Comment