使用Extjs中的Ext.data.Store时,利用Ext.data.proxy.Ajax的配置来获取后台返回数据,想对返回的响应数据进行二次处理。
Ext.data.proxy.Ajax配置中存在一个属性配置 extractResponseData(模板方法,以允许子类指定如何为阅读器获取响应。),参数是response,需要返回处理后的数据
extractResponseData ( response ) : Object TEMPLATE PRIVATE
Template method to allow subclasses to specify how to get the response for the reader.
PARAMETERS
response : Object
The server response
RETURNS :Object
The response data to be used by the reader
This is a template method. a hook into the functionality of this class. Feel free to override it in child classes.
写法一:
Ext.create('Ext.data.TreeStore', {
model: 'treeModel',
proxy: {
type: 'ajax',
method: 'POST',
url: 'getMenuTreeData.action',
reader: {
type: 'json'
},
extractResponseData: function(response) {
// 将响应的数据进行转换,具体的返回数据,可以自行打印响应参数进行查看
var result = Ext.util.JSON.decode(response.responseText);
// 将处理后的数据,重新赋值给响应的数据
response.responseText = Ext.util.JSON.encode(dealMenuTreeData(result))
// 返回响应数据
return response
},
},
autoLoad: true
});
写法二
Ext.create('Ext.data.TreeStore', {
model: 'treeModel',
proxy: {
type: 'ajax',
method: 'POST',
url: 'getMenuTreeData.action',
reader: {
type: 'json'
},
extractResponseData: function(response) {
// 将响应的数据进行转换,具体的返回数据,可以自行打印响应参数进行查看
var result = Ext.util.JSON.decode(response.responseText);
// 直接返回处理后的数据,我这里的数据是数组类型
return dealMenuTreeData(result)
},
},
autoLoad: true
});
原文地址:https://blog.csdn.net/zuohu2017/article/details/127085445
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_41454.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!