如何配置ExtJS 4 Store(代理和读取器)以读取元数据

bar*_*kin 8 proxy json model extjs extjs4

我的问题是除了totalRecords之外如何获取元数据,在我的例子中它是版本,代码,searchquery(请查看json).

{
"result": {
    "version":"1",
    "code":"200",
    "searchquery": "false",
    "totalRecords": "2",
    "account":[
            {
                "lastname": "Ivanoff", 
                "firstname": "Ivan", 
                "accountId":"1"
            },
            {
                "lastname": "Smirnoff", 
                "firstname": "Ivan", 
                "accountId":"2"
            }
        ]
}
Run Code Online (Sandbox Code Playgroud)

}

这是我的模型:

Ext.define("test.Account", {
    extend: "Ext.data.Model",
    fields: [
        {name: 'accountId', type: 'string'},
        {name: 'lastname', type: 'string'},
        {name: 'firstname', type: 'string'}    
    ]
});
Run Code Online (Sandbox Code Playgroud)

并存储:

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"
        }
    },

    listeners: {
        load: function(store, records, success) {
            console.log("Load: success " + success);     
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

使用此商店,我可以加载记录(帐户),但无法找到任何方法来访问其余字段.

先感谢您.

bar*_*kin 17

这是我的问题的解决方案.我在Proxy类中处理afterRequest事件,我可以获取响应数据,解析它并保存元数据.这是TestStore类的代理部分:

所以这是TestStore类的代理部分:

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);    
        }
    }
Run Code Online (Sandbox Code Playgroud)


sha*_*sha 1

看一下Ext.data.Proxy类和更具体的processResponse()方法。如果您需要提取任何其他数据 - 您将必须扩展标准类并更改该方法。