Store.sync() with new record does not import server-generated fields in response

这一生的挚爱 提交于 2020-01-05 03:31:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!