本文介绍了如何配置ExtJS 4 Store(代理和阅读器)来读取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是如何获取totalRecords之外的元数据,在我的情况下,它是版本,代码,searchquery(请看json)。

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

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

}

这是我的模型:

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

并存储:

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

使用这个商店我可以加载记录(帐户),找不到任何方法来访问其余的田野。

Using this store I am able to load records (account) and cannot find any methods to access rest of the fields.

提前谢谢。

推荐答案

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

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:

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

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

这篇关于如何配置ExtJS 4 Store(代理和阅读器)来读取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 14:44