Created
January 14, 2014 16:23
-
-
Save davydotcom/8421052 to your computer and use it in GitHub Desktop.
Ember data working with grails style json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DS.RESTAdapter.reopen({ | |
pathForType: function(type) { | |
return Ember.String.camelize(type); | |
} | |
}); | |
App.ApplicationSerializer = DS.RESTSerializer.extend({ | |
normalizePayload: function(type, payload) { | |
console.log("normalizing things"); | |
if(payload.data instanceof Array) { | |
payload[Ember.String.pluralize(type.typeKey)] = payload.data; | |
delete payload.data; | |
} else { | |
console.log(Ember.String.singularize(type.typeKey)) | |
payload[Ember.String.singularize(type.typeKey)] = payload.data; | |
delete payload.data; | |
} | |
console.log(payload) | |
return payload; | |
}, | |
serializeIntoHash: function(data, type, record, options) { | |
var object = this.serialize(record, options); | |
for(var key in object) { | |
data[key] = object[key]; | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment