Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ember data to save multiple records via post

Does anyone know of any working examples of overriding ember-data's DS.Adapter to save all records at once?

I'd like to stringify my entire array of records and send them to my server. I don't have much flexibility on the server to use anything but the existing API which is just a perl CGI script. Any help in the right direction would be appreciated.

like image 389
ac84 Avatar asked Feb 19 '14 23:02

ac84


1 Answers

What I did was iterate over the ember-data models, serialized them, saved them into a json object that matched server requirements, and executed post request.

var identifiedResponse = []
this.store.filter(key, function (record) {
   return !!record.get('name')
}).then(function(resp) {
    identifiedResponse.push(item.serialize())
    })
jQuery.ajax({
       url: url,
       type: "POST",
       data: identifiedResponse,
       contentType: "application/json",
       dataType: 'json',
       xhrFields: {
       withCredentials: true
       }
 })
like image 139
JJJ Avatar answered Sep 30 '22 18:09

JJJ