Use proxy extended Ext.data.Operation

I added Ext.data.Operationto implement a custom method commitRecords.

The class is Ext.data.Operationused for all communication between stores and their proxies.

The method is commitRecordsspecifically used to update data in the data warehouse in accordance with the data received from the proxy writer.

I cannot figure out how to configure my proxies to use the advanced version Ext.data.Operation.

I sketched a package Ext.data.*, but could not find where it is being created Ext.data.Operation, so I will know which class should use this new extended class Ext.data.Operationwith a custom commitRecords>.

Has anyone else extended this earlier, could give me some pointers?

+5
source share
1 answer

I found it, the method batch Ext.data.Proxyis an object Ext.data.Operationcreated to be sent to the server.

I expanded with a Ext.data.proxy.Ajaxnew method batch, where I simply disabled new Ext.data.Operationfor my own class of operations.

EDIT

Just because you asked Dmitry B. A short story about why I had to implement my own commitRecords method is that I need the β€œinternalId” data fields for the data that match the actual ID field of the database record. I will not go into why it is too confusing for me to express, but here is what I did:

, commitRecords store.sync(), , Ajax, , .

commitRecords , "internalId" .

, , , , , internalId, commitRecords, , .

, "create_time", commitRecords , "create_time" "internalId" .

Ext.data.Operation, :

Ext.define('MyApp.ux.QueryOperation', {
    extend: 'Ext.data.Operation',

    /** 
     * Use the date_created timestamp if we cant match to an ID.
     * This allows client records that did not previously exist on the server
     * to be updated with the correct server ID and data
     * NB: All implementing data models require a "date_created" field.
     */
    commitRecords: function (serverRecords) {
        var me = this,
            mc, index, clientRecords, serverRec, clientRec;
        if (!me.actionSkipSyncRe.test(me.action)) {
            clientRecords = me.records;
            if (clientRecords && clientRecords.length) {
                if (clientRecords.length > 1) {
                    mc = new Ext.util.MixedCollection();
                    mc.addAll(serverRecords);
                    Ext.each(clientRecords, function(clientRec) {
                        serverRec = mc.findBy(function(record) {
                            var clientId = clientRec.getId(),
                                clientTime = clientRec.get('date_created').getTime(),
                                serverTime = record.get('date_created').getTime();
                                if(clientId && record.getId() === clientId) {
                                    return true;
                                }
                                // timestamp can be within 2ms of record
                                // (it seems to change slightly in serialization)
                                return (clientTime > serverTime - 2 && clientTime < serverTime + 2);
                        });
                        me.updateClientRecord(clientRec, serverRec);
                    });
                } else {
                    clientRec = clientRecords[0];
                    serverRec = serverRecords[0];
                    me.updateClientRecord(clientRec, serverRec);
                }
                if (me.actionCommitRecordsRe.test(me.action)) {
                    for (index = clientRecords.length; index--; ) {
                        clientRecords[index].commit();
                    }
                }
            }
        }
    },

});

, , -, Operation. , , batch, , new Ext.data.Operation, new MyApp.ux.QueryOperation ( Operation ). commitRecords, . "proxy.query", , :

Ext.define('MyApp.store.MyStore', {
    extend: 'Ext.data.Store',
    requires: [
        'ST.ux.QueryProxy',
    ],
    title: 'Student',
    model: 'MyApp.model.MyModel',
    proxy: {
        type: 'query',
        // ... ^^^^^ uses my QueryProxy now
        // other configs...
    }
});

( , - , , .)

+4

All Articles