I have to store a data from ajax call to model.Now I am using "pushPayload" to save the data to my model.But it is throwing error
serializer.pushPayload is not a function
In controller I am doing something like this after the ajax call.
currentState.store.pushPayload('discover',result)
serializer (discover.js)
export default DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin,{
isNewSerializerAPI: true,
primaryKey:'pk',
normalize: function(typeClass, hash) {
var fields = Ember.get(typeClass, 'fields');
fields.forEach(function(field) {
var payloadField = Ember.String.underscore(field);
if (field === payloadField) { return; }
hash[field] = hash[payloadField];
delete hash[payloadField];
});
return this._super.apply(this, arguments);
}
});
How do I save the data recieved from server to my model.The reponse is an array of object
store.pushPayload internally uses either application serializer's pushPayload function or the given model's specific serializer's pushPayload function. In your case model specific serializer is of JSONSerializer type which doesn't have the required function.
You can refer JSONAPISerialzer, which has the pushPayload function and try to replica it in your JSONSerializer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With