vendredi 2 octobre 2015

Normalizing the name of JSON name

I'm using the ember-data to get all my events on my route api: /api/events, the problem is that the JSON that returns does not comply with the request by Ember, is there anything I can do to fix it?

This is my code:

Adapter and Serializer:

SiteApp.ApplicationAdapter = DS.RESTAdapter.extend({
  namespace: 'api'
});
SiteApp.ApplicationSerializer = DS.RESTSerializer.extend({
  primaryKey: '_id'
});

EventModel:

SiteApp.Event = DS.Model.extend({
  description : DS.attr(),
  name        : DS.attr().
  type        : DS.attr()
});

And in the Route i have the this.store.findAll('event');

The JSON is like this:

{
  data: [{
    _id: "55f660bdd80a0fd2e298f333",
    attributes: {
      description: "test",
      name: "name",
      is_active: false
    },
    type: "events"
  }]
}

Which will work if i change the "data" for "event", but i can't, that's not a option.

Is possible resolve with other way? Or i'm f*up? haha

Thanks.




Aucun commentaire:

Enregistrer un commentaire