I have an Ember/EmberData (version 2.1.0) application that is to display a list of posts (created from a json payload) on the home page, with the route
this.route("posts", { path: "/" });
However, the posts retrieved from the server are not in the format expected by EmberData i.e. they do not have a top level namespace. Therefore, I created a file
serializers/application.js
and included an extractSingle and an extractArray function in it, but neither of them are getting called, and the error message is therefore not goig away
Error while processing route: posts Assertion Failed: You must include an 'id' for undefined in an object passed to 'push
This error was preceeded by a warning:
`WARNING: "Encountered "0" [and "1"] in payload, but no model was found for model name "0" (resolved model name using em@serializer:posts.modelNameFRomPayloadKey("0")
I also created a file
serializers/posts.js
and included the same functions there, as well (extending the ApplicationAdapter) but neither of them are getting called also
Code from /serializers/application.js
import DS from 'ember-data'
export default DS.RESTSerializer.extend({
extractSingle: function(store, type, payload, id){
var convertedPayload = {};
convertedPayload[type.modelName] = payload;
convertedPayload.id = id;
return this._super(store, type, convertedPayload, id}
},
extractArray: function(store, type, payload){
var convertedPayload = {};
convertedPayload[type.modelName = payload;
return this._super(store, type, convertedPayload);
},
serializeIntoHash: function(hash, type, record, options){
//ommitted
}
}
Aucun commentaire:
Enregistrer un commentaire