Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to use pushPayload in ember

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

like image 939
nandanself Avatar asked Jan 27 '26 00:01

nandanself


1 Answers

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.

like image 148
Suresh Kumar Avatar answered Jan 28 '26 21:01

Suresh Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!