问题
I have a grid with row-editing enabled. When I add a row and call store.sync(), the server generates certain fields on that record, and returns the full record info in the response. However, ExtJS does not seem to update its copy of the record, except for the id. Is there a way to make it do that, or do I need to write custom code?
This is an excerpt of the grid's controller:
doneEdit: function (editor, e, eOpts) {
var me = this;
//
// Set up loading mask on grid during update (if record changed and is valid)
//
if (e.record.dirty && e.record.isValid()) {
e.grid.showUpdatingMask();
e.store.sync({
success: me.onSaveSuccess,
failure: me.onSaveFailure,
scope: me
});
}
else {
me.cancelEdit(editor, e, eOpts);
}
},
//
// onSaveSuccess() is only used for row editor grids
//
onSaveSuccess: function (batch, options) {
var me = this,
grid = me.getGrid();
grid.getStore().filter([]); // re-run whatever filters already exist, and sort.
grid.hideMask();
// update read-only active store if specified by sub-class
if(me.activeStore) {
// $TODO: handle load failure
me.activeStore.load();
}
},
回答1:
I had the same problem (Ext 4.2.1). The reason was that I forgot to set the idProperty on the reader default is "id", mine is "_id". Ext silently failed to update the record because it didn't recognize a matching id. Now it works like a charm.
So make sure the response is in the correct format expected by your reader (root, idProperty, model definition, ...)
来源:https://stackoverflow.com/questions/16219638/store-sync-with-new-record-does-not-import-server-generated-fields-in-response