Reputation: 859
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!
Upvotes: 0
Views: 76
Reputation: 3669
Use primaryModelClass.modelName
instead requestType
.
requestType
is just string like 'findAll', 'findRecord' and etc.
export default DS.RESTSerializer.extend({
normalizeResponse: function(store, primaryModelClass, payload, id, requestType) {
var pluralTypeKey = Ember.String.pluralize(primaryModelClass.modelName);
payload[pluralTypeKey] = payload['data'];
delete payload['data'];
return this._super(store, primaryModelClass, payload, id, requestType);
}
Working jsbin: http://emberjs.jsbin.com/weyuwixoli/edit?js,output
Upvotes: 2