jQuery MiniUI

 找回密码
 立即注册
查看: 12748|回复: 5
打印 上一主题 下一主题

datagrid中接收到服务器返回的json格式数据不满足规范处理 [复制链接]

Rank: 2

跳转到指定楼层
楼主
发表于 2018-11-27 11:18:18 |只看该作者 |倒序浏览
在使用mini-datagrid时,服务端返回是的数据必须是如下格式
{total:11,
data:[
        {url:"BE.ico",name:"比利时"},
        {url:"CZ.ico",name:"捷克"},
]}
但是目前服务端是一一上线运行项目,无法按照现datagrid要求重新构造返回数据,服务端返回数据格式如下:
{
code: "SUCCEED",
data: {
"totalCount": "2",
"list": [
{
"id": "682265633886208",
"status": 1,
"createBy": "",
"createTime": "2018-05-01 16:13:51"
},
{
"id": "4363087427670016",
"status": 1,
"createBy": "",
"createTime": "2018-05-03 15:09:42"
}]
},
"sign": "",
"message": "操作成功",
"isSucceed": true,
"timestamp": "1543283213706"
}
想请教一下,有什么好的办法可以在前端进行重新构造数据,之前是通过ajax方式从服务端获取数据后,采用grdi.setData(data)方式,对datagrid赋值,但是发现当点击datagrid底部的刷新或分页时,无法手动调自定义的ajax方法,导致因数据格式错误,无法重新对datagrid重新绑定数据

Rank: 8Rank: 8

沙发
发表于 2018-11-27 11:30:33 |只看该作者
直接用url加载,表格上设置
totalField="totalCount"
dataField="list"

Rank: 2

板凳
发表于 2018-11-28 10:00:59 |只看该作者
由于服务端返回的json中,实际数据是在data的子节点中,我通过设置totalField="data.totalCount",dataField="data.list"便可以成功展现数据,但是我当在使用combox控件时,采用valueField="data.id" textField="data.alias" 方式设置,发现无法绑定数据,想请教一下,有什么解决办法么。我combox控件获取到的json数据格式如下:
{
"appSeqNo": "",
"data": [
{
"id": "7",
"status": 1,
"createTime": "2018-11-27 18:55:55",
"updateTime": null,
"sort": null,
"remark": null,
"alias": "lemur-gen",
"author": "lihangyu",
"userId": 0,
"codePackage": "cn.afterturn.gen.modular.code",
"xmlPackage": "MET-INF.mapping",
"jsPackage": "static.modular.code",
"htmlPackage": "WEB-INF.view.modular.code",
"localPath": "D:\\mySpace\\lemur\\lemur-generation\\gen-admin\\src\\main",
"copyright": null,
"encoded": "UTF-8"
},
{
"id": "8",
"status": 1,
"createTime": "2018-11-27 18:55:55",
"updateTime": null,
"sort": null,
"remark": null,
"alias": "review-rest",
"author": "JueYue",
"userId": 1,
"codePackage": "cn.allisone.review.rest.modular.review",
"xmlPackage": "",
"jsPackage": "",
"htmlPackage": "",
"localPath": "",
"copyright": null,
"encoded": "UTF-8"
}
],
"gencode": "SUCCEED",
"serSeqNo": "",
"appId": "",
"sign": "",
"message": "操作成功",
"isSucceed": true,
"timestamp": "1543369562563"
}

Rank: 2

地板
发表于 2018-11-28 10:29:09 |只看该作者
felt 发表于 2018-11-27 11:30
直接用url加载,表格上设置
totalField="totalCount"
dataField="list"

由于服务端返回的json中,实际数据是在data的子节点中,我通过设置totalField="data.totalCount",dataField="data.list"便可以成功展现数据,但是我当在使用combox控件时,采用valueField="data.id" textField="data.alias" 方式设置,发现无法绑定数据,想请教一下,有什么解决办法么。我combox控件获取到的json数据格式如下:
{
"appSeqNo": "",
"data": [
{
"id": "7",
"status": 1,
"createTime": "2018-11-27 18:55:55",
"updateTime": null,
"sort": null,
"remark": null,
"alias": "lemur-gen",
"author": "lihangyu",
"userId": 0,
"codePackage": "cn.afterturn.gen.modular.code",
"xmlPackage": "MET-INF.mapping",
"jsPackage": "static.modular.code",
"htmlPackage": "WEB-INF.view.modular.code",
"localPath": "D:\\mySpace\\lemur\\lemur-generation\\gen-admin\\src\\main",
"copyright": null,
"encoded": "UTF-8"
},
{
"id": "8",
"status": 1,
"createTime": "2018-11-27 18:55:55",
"updateTime": null,
"sort": null,
"remark": null,
"alias": "review-rest",
"author": "JueYue",
"userId": 1,
"codePackage": "cn.allisone.review.rest.modular.review",
"xmlPackage": "",
"jsPackage": "",
"htmlPackage": "",
"localPath": "",
"copyright": null,
"encoded": "UTF-8"
}
],
"gencode": "SUCCEED",
"serSeqNo": "",
"appId": "",
"sign": "",
"message": "操作成功",
"isSucceed": true,
"timestamp": "1543369562563"
}

Rank: 8Rank: 8

5#
发表于 2018-11-28 10:29:22 |只看该作者
buyiyanqi 发表于 2018-11-28 10:00
由于服务端返回的json中,实际数据是在data的子节点中,我通过设置totalField="data.totalCount",dataField ...

你写错了
dataField="data"  
textField="alias"
valueField="id"

Rank: 6Rank: 6

6#
发表于 2020-3-24 12:20:26 |只看该作者
felt 发表于 2018-11-27 11:30
直接用url加载,表格上设置
totalField="totalCount"
dataField="list"

我在mini-treegrid中设置totalField和dataField都不管用嘛

Archiver|普加软件

GMT+8, 2024-11-25 14:15 , Processed in 1.026539 second(s), 10 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部