jeudi 16 octobre 2014

Model's date sent to server as millisecond string, not number

Is the intended behavior of a model's proxy to write a string instead of a number when the dateFormat is U (milliseconds since 1970) or timestamp (Unix timestamp, same as U)?

I ask, because my server expects a date as milliseconds as number, but the model's proxy is sending milliseconds as string, so the POST request is failing:


This proxy code:



Code:



writer:{
type:'json',
allowSingle : true,
dateFormat: 'timestamp'
}

Produces these post values in console:


Code:





  • start: "1395979200"

  • stop: "1414728000"



When I add a transform function to the writer to do a parseInt on the date values, the values are sent as numbers:

Code:



writer:{
type:'json',
allowSingle : true,
dateFormat: 'timestamp', //this is being sent as a string
transform: {
fn: function(data, request) {
data.start = parseInt(data.start);
data.stop = parseInt(data.stop);
return data;
}
}
}

Produces this POST request:

Code:





  • start: 1395979200

  • stop: 1414728000







Model's date sent to server as millisecond string, not number

Aucun commentaire:

Enregistrer un commentaire