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

前端 未结 3 928
攒了一身酷
攒了一身酷 2021-02-03 13:25

My question is how to get metadata besides totalRecords, in my case it is version, code, searchquery (please look at json).

{
\"result\": {
    \"version\":\"1\         


        
3条回答
  •  野性不改
    2021-02-03 14:00

    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);     
            }
        }
    });
    

提交回复
热议问题