How to configure ExtJS 4 Store (proxy and reader) to read metadata How to configure ExtJS 4 Store (proxy and reader) to read metadata json json

How to configure ExtJS 4 Store (proxy and reader) to read metadata


Here is solution for my problem. I am handling afterRequest event in the Proxy class where I can get response data, parse it and save metadata. This is proxy part of the TestStore class:

So here is proxy part from the TestStore class:

proxy: {        type: "ajax",        url: "/users.json",          reader: {            type    : 'json',            root    : 'gip.account',            totalProperty: "gip.totalRecords",            searchquery: "searchquery"        },        afterRequest: function(req, res) {            console.log("Ahoy!", req.operation.response);            }    }


It is possible to use the 'metachange' event of the store.

All the non-extjs specific information can be grouped in JSON in the separate object:

{    "result": {        "totalRecords": "2",        "account":[            {                "lastname": "Ivanoff",                 "firstname": "Ivan",                 "accountId":"1"            },            {                "lastname": "Smirnoff",                 "firstname": "Ivan",                 "accountId":"2"            }        ]    },    "myMetaData": {        "version":"1",        "code":"200",        "searchquery": "false"    }}

The store is configured as

Ext.define("test.TestStore", {    extend: "Ext.data.Store",    model: "test.Account",    proxy: {        type: "ajax",        url: "users.json",          reader: {            type    : 'json',            root    : 'result.account',            totalProperty: "result.totalRecords",            metaProperty: 'myMetaData'        }    },    listeners: {        metachange: function(store, meta) {            console.log("Version " + meta.version + "Search query " + meta.searchQuery);             }    }});


Take a look at Ext.data.Proxy class and more specifically processResponse() method. If you need to extract any additional data - you will have to extend standard class and change that method.