javascript - creating an ember-data application serialzer -


i've been trying use ember data few days now. problem api have not match strcuture ember-data receive.

item:

{     "data": {         "id": 1,         "username": "rodzzlessa",         "slug": "rodzzlessa"      } } 

collection:

{ "data": [     {         "id": 34,         "name": "hdg common nails 50lbs",         "slug": "hdg-common-nails-50lbs4569",         "description": "accusantium ipsam impedit omnis sint dolorum.",         "image_src": "nail-box-angle.png",         "categories": {             "data": [                 {                      "id": 2,                      "name": "nails",                     "image_src": "nails-icon.png"                 }              ]          }      }   ] } 

from i've seen need modify extractsingle , extractarray methods. there isn't online resource showing methods doing , how modify them. check ember-data api guide example specific , not application serializer seems easier problem solving. tried finding ember-data book don't exist yet. there online resources me?

/***** update far ******/

so able create application serializer handle collection , items:

export default ds.restserializer.extend({      extractarray: function(store, typeclass, payload) {         var root_key = ember.inflector.inflector.pluralize(typeclass.typekey);          payload[root_key] = payload.data;         delete payload.data;          return this._super(store, typeclass, payload);     },      extractsingle: function(store, typeclass, payload, id){         var root_key = typeclass.typekey;          payload[root_key] = payload.data;         delete payload.data;          return this._super(store, typeclass, payload, id);     } }); 

now problem have dealing relationships started messing around normalize method have far:

normalize: function(typeclass, hash, prop){         self = this;          typeclass.eachrelationship(function(key, relationship){             if(relationship.kind === "hasmany"){                 if( ! hash[key]){                     return hash;                 }                  var hashed = hash[key].data;                  hash[key] = hashed;                  return hashed;             }         });          return this._super(typeclass, hash, prop);     } 

now error ember-data this:

assertion failed: ember data expected number or string represent record(s) in `categories` relationship instead found object 


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -