extjs中元数据_如何配置ExtJS 4 Store(代理和阅读器)来读取元数据

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"

}

]

}

}

Here is my model:

Ext.define("test.Account", {

extend: "Ext.data.Model",

fields: [

{name: 'accountId', type: 'string'},

{name: 'lastname', type: 'string'},

{name: 'firstname', type: 'string'}

]

});

And store:

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.

Thank you in advance.

解决方案

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

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值