vendredi 16 mai 2014

Single record in store is note passed as an Array in Rest Sync

Hello,

So I have the follwing model and store:



Code:



Ext.define('MyApp.Map.Marker', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{name: 'id', type: 'int'},
{name: 'latitude', type: 'float'},
{name: 'longitude', type: 'float'},
]
});


var markerStore = Ext.create('Ext.data.Store', {
model: 'MyApp.Map.Marker',
proxy: {
type: 'rest',
batchActions: true,
appendId: false,
reader: { type: 'json', root: 'vertices' },
writer: {type: 'json', root: 'vertices'},
api: {
create: '/vertices/batch',
read: '/vertices',
update: '/vertices/batch',
destroy: '/vertices/batch'
}
},
listeners: {
wirte: function(){
console.log("I've written!");
}
}
});

So, as you can see, I configured to sync in batch, making only 3 request (one for create, one for update, and one for delete) instead of doing one for each modified record.

Everything is working fine except that when I have only one recordo to create, for example, my vertices param is a object instead of an array.


Like this. Two or more records:



Code:



"vertices"=>[{"id"=>0, "latitude"=>-22.891990243585727, "longitude"=>-47.20001220703125}, {"id"=>0, "latitude"=>-22.86668527847696, "longitude"=>-47.05101013183594}]

Single record


Code:



"vertices"=>{"id"=>0, "latitude"=>-22.916025590238377, "longitude"=>-47.330474853515625

Is there a way I can force ExtJS to put this single record in an Array?

Is that a normal Javascript behavior, or is just ExtJS? Because, for me, makes no sense, since it's a batch operation, to send the single record out of an Array.





Aucun commentaire:

Enregistrer un commentaire