ExtJS version is ext-4.0.7-gpl
.
When syncing a Store, the server returns me the same object in JSON format, but populated with generated Ids, that I need to put into my store data. The identifiers are in enclosed entities, like this:
{
"id": 46,
"name": "Excel",
"typeExt": [{
"ext": "xls",
"id": "137",
"isMain": "false",
}, {
"ext": "xslx",
"id": "136",
"isMain": "false",
}]
}
So the ids 137
and 136
are generated on server-side.
I am trying to make it in a store's proxy (edit: Ajax type) (which itself could be wrong):
proxy.afterRequest = function(request) {
if (request.action === 'create' && request.records.length == 1) {
me.store.autoSync = false;
var created = Ext.JSON.decode(request.operation.response.responseText);
request.records[0].set('id', created.id);
request.records[0].set('typeExt', created.typeExt);
//request.records[0].modified = {};
//request.records[0].dirty = false;
me.store.autoSync = true;
}
if (request.action === 'update' && request.records.length == 1) {
var updated = Ext.JSON.decode(request.operation.response.responseText);
me.store.autoSync = false;
request.records[0].set('typeExt', updated.typeExt);
me.store.autoSync = true;
}
};
See the commented variants.
If I don't set autoSync
to false
, it gets looped infinitely.
If I don't clear those read-only
fields modified
and dirty
, the modified records are included in the next syncronization request, if I edited another record, it sends an Array of records which breaks my server-side service.
If I clear dirty
and modified
like it is shown in the commented lines, the update operation works only once. I press Update button in RowEditing plugin dialog, but it never sends the needed request to the server for the second time.
In the latter case I guess I broke something by hand-editing the readonly fields, but I can not find what.
How do people usually handle issues liek this?
PS.
request.records[0].commit(true); || request.records[0].editing = false;
|| request.records[0].beginEdit();
Were tried with no seccess too.