0

Before I use json-api, I custom ember data api like this:

import DS from 'ember-data';
import config from './../config/environment';

export default DS.Model.extend({
  ...

  useRepairPackage(repairPackageId) {
    Ember.$.ajax({url: `${config.host}/${config.namespace}/quotations/${this.get('id')}/use_repair_package.json`, type: "PATCH", data: {...}}).then((result)=> { 
      return this.reload();
    }); 
  }
});

But when I use json-api, data: {...} is more complex and I must make up json by myself.

It had best way to solve this problem? Thanks.

JeskTop
  • 481
  • 1
  • 4
  • 20

1 Answers1

1

Even if you use the JSONAPIAdapter for your application, you can still use model.toJSON() to return a flat data JSON object(uses JSONSerializer) to use anywhere like in your ajax request.

See toJSON.

P.S. Have you seen https://github.com/mike-north/ember-api-actions?

knownasilya
  • 5,998
  • 4
  • 36
  • 59