PDA

View Full Version : Store write array under a property name



XPEHBAM
17 May 2013, 11:12 AM
I have a model like this:



Ext.define('Policy', {
extend: 'Ext.data.Model',


fields: [
{
name: 'id',
type: 'sting',
phantom: true,
convert: function(value, record) {
return record.get('a') + '@' +
record.get('b');
}
},
{name: 'a', type: 'string'},
{name: 'b', type: 'string'}]
});
Where the PK of each record is a and b. The store looks like this:



Ext.define('Store', {
extend: 'Ext.data.Store',
model: 'Policy',
autoLoad: true,


proxy: {
type: 'rest',
simpleSortMode: true,
batchActions: true,
reader: {
type: 'json',
root: 'data',
idProperty: 'id'
},
writer: {
nameProperty: 'mapping'
},
api: {
create:'/batch',
read: '/policies',
update: '/batch',
destroy: '/batch'
}
}
});
How can I configure the store so that when it POSTS to /batch when calling store.sync(), the payload looks like this and only consists of dirty records:



{
"policies": [{
"a": "AA",
"b": "BB",
}, {
"a": "AAA",
"b": "BBB"
},...]
}
where there is a policies property and under it is an array of dirty policies.

slemmon
20 May 2013, 11:34 AM
I think you're going to need to extend store and write your own implementation of one or more of the following methods:

getNewRecords()
getUpdatedRecords()
getRemovedRecords()
or
sync()