samedi 28 février 2015

Convert Emberjs recordArray model to JSON

Disclaimer: I am new to Ember.


With that being said, I am trying to convert an Ember recordArray to a JSON string so that I can send it to my server for processing.


I have the following Ember model:



Loads.Load = DS.Model.extend({
pickupStartTime: DS.attr('string'),
pickupEndTime: DS.attr('string'),
pickupLocation: DS.attr('string'),
pickupGeocode: DS.attr('string'),
pickupWeight: DS.attr('number'),
pickupTicket: DS.attr('string'),
dropoffStartTime: DS.attr('string'),
dropoffEndTime: DS.attr('string'),
dropoffLocation: DS.attr('string'),
dropoffGeocode: DS.attr('string'),
dropoffWeight: DS.attr('number'),
dropoffTicket: DS.attr('string'),
commodity: DS.attr('string'),
isCompleted: DS.attr('boolean'),
shortPickupStartTime: function(){
var time = this.get('pickupStartTime');
if(time){
var split = time.split(" ");
return split[4];
}else{
return " ";
}
}.property('pickupStartTime'),
shortPickupEndTime: function(){
var time = this.get('pickupEndTime');
if(time){
var split = time.split(" ");
return split[4];
}else{
return " ";
}
}.property('pickupEndTime'),
shortDropoffStartTime:function(){
var time = this.get('dropoffStartTime');
if(time){
var split = time.split(" ");
return split[4];
}else{
return " ";
}
}.property('dropoffStartTime'),
shortDropoffEndTime: function(){
var time = this.get('dropoffEndTime');
if(time){
var split = time.split(" ");
return split[4];
}else{
return " ";
}
}.property('dropoffEndTime')
});


I have the following action in my controller:



var self = this;

Ember.RSVP.hash({
//loads is an array of records
loads: this.store.find('load')
}).then(function (data) {
$.ajax({
type: "POST",
data: { Loads: JSON.stringify(data.loads) },
url: "api/buildexcelsheet",
contentType: "application/json",
success: function (message) {
self.set('uri', message);
}
});
});


When I run this action from the controller I get the following error:



Uncaught Error: Assertion Failed: TypeError: Converting circular structure to JSON


Since I'm new to Ember, I'm unsure as to what I'm doing wrong.


Any help would be greatly appreciated.


Thanks!





Aucun commentaire:

Enregistrer un commentaire