arpho
arpho

Reputation: 1646

extjs4 proxy rest multiple request issue

Hi I am encountering a wierd behavior with my application:when I modify an item and then my proxy doas a put request, the first time is ok, the second time it sends two requests: the first with the data of the previous one, the second one with the actual data, the third time it sends three requests, onmy system it is not a big issue, because at end I get the right value on my database, but on my customer's system the result it is not always correct. Then I would like to remove this behavior.

this is my store:

Ext.create('Ext.data.Store',
        {
            storeId: 'bbCompaniesStore',
            model:'Company',
            pageSize: pageSize,
            proxy:
            {
                idProperty : '_id',
                type: 'rest',
                url: 'data/companies/',
                autoload: true,
                noCache: true,
                sortParam: undefined,
                actionMethods:
                 {
                        create : 'PUT',
                        read   : 'GET',
                        update : 'POST',
                        destroy: 'DELETE'
                    },

                reader:
                {
                    type: 'json',
                    root: 'data',
                    totalProperty: 'total'
                },

            },// proxy
            listeners: {
                exception: function(proxy, response, operation) {
                    Ext.gritter.add({
                        title: MongoVision.text['action.' + operation.action] || operation.action,
                        text: (operation.error ? operation.error.statusText : null) || MongoVision.text.exception
                    }); 

                    // Ext JS 4.0 does not handle this exception!
                    switch (operation.action) {
                        case 'create':
                            Ext.each(operation.records, function(record) {
                                record.store.remove(record);
                            });
                            break;

                        case 'destroy':
                            Ext.each(operation.records, function(record) {
                                if (record.removeStore) {
                                    record.removeStore.insert(record.removeIndex, record);
                                }
                            });
                            break;
                    }
                }
                }
        }
);

this is my model:

Ext.define('Company',
{
extend: 'Ext.data.Model',
fields: [
        {
            name :  'id',
            type : 'string'
        },
        {
            name :'firm',
            type : 'string',
            allowBlank: false
        },{
            name : 'p'
        },
        {
            name: 'linee'
        },
        {
            name : 'c'
        },
        {
            name : 'data',
            type: 'date'
        },
        {
            name :'note'
        },
        { 
            name :'paese'
        },
        {
            name : 'email'
        },
        {
            name : 'telefono'
        },
        {
            name : 'type'
        },
        {
            name : 'website'
        },
        {
            name : 'session_id'
        },
        {
            name : 'group_id'
        }


],
proxy : {
    type : 'rest',
    url : 'data/companies/'
}

}
);

after googling around I found a similar issue for extjs3, with no solution, I think it is strange that after so long time, there is no yet a solution; it should work now

Upvotes: 0

Views: 783

Answers (1)

blagerweij
blagerweij

Reputation: 3421

I faced the same issue, resolved it by simply passing batchActions: true when creating the Proxy. The default behavior for 'rest' proxies is to turn off batching.... (See extjs/src/data/proxy/Rest.js)

Upvotes: 1

Related Questions