Advertisement
Guest User

Untitled

a guest
May 24th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. save: function(){
  2. var url = "/api/v1/player_evaluations";
  3. var recordType = "player_evaluation";
  4. var topLevelKey = `${recordType}s`;
  5. var itemsToSave = this.get('myItems');
  6.  
  7. var store = this.get('store');
  8. var type = "post";
  9. var dataType = "json";
  10. var contentType = "application/json; charset=utf-8";
  11.  
  12. var recordCollection = Ember.A();
  13. for(var i = 0; i < itemsToSave.length; i++) {
  14. recordCollection.push store.createRecord(recordType, itemsToSave[i]);
  15. }
  16.  
  17. var paylaod = {}
  18. var paylaod[topLevelKey] = recordCollection.map(function(record) { record.serialize() });
  19. var data = JSON.stringify(payload);
  20. Ember.$.ajax({ url, type, dataType, data, contentType }).then function(data) { store.pushPayload recordType, data }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement