mardi 22 septembre 2015

Ember Data 2.0 model won't get records

I can't seem to get Ember Data to work with my API format. Right now my API is like so:

{
  data: [
    {
      id: 1,
      name: "Some Company",
      primary_contact: "Bob Smith"
    },
    {
      id: 2,
      name: "Another Company",
      primary_contact: "Bob Smith"
    },
  ]
}

I know that Ember wants the key to be organizations rather then data but that is just not possible. I've been trying to get it working with a serializer, and I don't know if I'm even on the right track. Here is what I currently have.

export default DS.RESTSerializer.extend({
  normalizeResponse: function(store, primaryModelClass, payload, id, requestType) {
  var pluralTypeKey = Ember.String.pluralize(requestType.typeKey);
  payload[pluralTypeKey] = payload['data'];
  delete payload['data'];

  return this._super(store, primaryModelClass, payload, id, requestType);
}

Any help would be GREATLY appreciated!




Aucun commentaire:

Enregistrer un commentaire