在写表格时遇到,后端返回的数据是对象,并且缺少字段
1.每一条数据加上 一个字段
2.将对象转成数组文章来源:https://www.toymoban.com/news/detail-615243.html
以下是数据文章来源地址https://www.toymoban.com/news/detail-615243.html
{
"groupA": {
"groupName": null,
"orgName": null,
"orgId": null,
"allPeoper": "813",
"all": "1396",
"checkFa": "917",
"checkFaYsfa": "19",
"checkFaFyxjj": "178",
"checkFaQdzybb": "1",
"checkFaByxjj": "467",
"checkFaFqtbb": "15",
"checkFaFwbb": "46",
"checkFaN": "103",
"checkFaFyxjjOrQdzybb": "1",
"checkFaOther": "87",
"checkJzc": "479",
"checkJzcBls": "149",
"checkJzcCa": "0",
"checkJzcAqbb": "6",
"checkJzcQtlxbb": "39",
"checkJzcN": "355",
"checkJzcOther": "79",
"checkFitY": "0",
"checkFitYX": "0",
"checkFitPositive": "0"
},
"groupB": {
"groupName": null,
"orgName": null,
"orgId": null,
"allPeoper": "1286",
"all": "1486",
"checkFa": "1282",
"checkFaYsfa": "23",
"checkFaFyxjj": "201",
"checkFaQdzybb": "6",
"checkFaByxjj": "619",
"checkFaFqtbb": "40",
"checkFaFwbb": "84",
"checkFaN": "156",
"checkFaFyxjjOrQdzybb": "0",
"checkFaOther": "153",
"checkJzc": "204",
"checkJzcBls": "35",
"checkJzcCa": "0",
"checkJzcAqbb": "1",
"checkJzcQtlxbb": "9",
"checkJzcN": "178",
"checkJzcOther": "16",
"checkFitY": "334",
"checkFitYX": "701",
"checkFitPositive": "210"
},
"groupC": {
"groupName": null,
"orgName": null,
"orgId": null,
"allPeoper": "553",
"all": "553",
"checkFa": "0",
"checkFaYsfa": "0",
"checkFaFyxjj": "0",
"checkFaQdzybb": "0",
"checkFaByxjj": "0",
"checkFaFqtbb": "0",
"checkFaFwbb": "0",
"checkFaN": "0",
"checkFaFyxjjOrQdzybb": "0",
"checkFaOther": "0",
"checkJzc": "553",
"checkJzcBls": "149",
"checkJzcCa": "0",
"checkJzcAqbb": "2",
"checkJzcQtlxbb": "29",
"checkJzcN": "426",
"checkJzcOther": "96",
"checkFitY": "31",
"checkFitYX": "315",
"checkFitPositive": "8"
},
"all": {
"groupName": null,
"orgName": "重庆癌症中心",
"orgId": null,
"allPeoper": "2652",
"all": "3435",
"checkFa": "2199",
"checkFaYsfa": "42",
"checkFaFyxjj": "379",
"checkFaQdzybb": "7",
"checkFaByxjj": "1086",
"checkFaFqtbb": "55",
"checkFaFwbb": "130",
"checkFaN": "259",
"checkFaFyxjjOrQdzybb": "1",
"checkFaOther": "240",
"checkJzc": "1236",
"checkJzcBls": "333",
"checkJzcCa": "0",
"checkJzcAqbb": "9",
"checkJzcQtlxbb": "77",
"checkJzcN": "959",
"checkJzcOther": "191",
"checkFitY": "365",
"checkFitYX": "1016",
"checkFitPositive": "218"
}
}
// 获取数据
async getTableList () {
const res = await get_SC_RCTList(this.search)
// 定义空数组,接收处理完的数据
let list = []
if (res.code === 200) {
Object.keys(res.data).forEach(key => {
// 拿到每一项
const item = res.data[key]
switch (key) {
case 'all':
item.groupName = "合计";
break;
case "groupA":
item.groupName = "肺肠A组";
break;
case "groupB":
item.groupName = "肺肠B组";
break;
case "groupC":
item.groupName = "肺肠C组";
break;
}
list.push(item)
})
// 要求数据是0,需要处理
list.map(item => {
if (item.groupName === '肺肠C组') {
item.checkFa = item.checkFa == '0' ? '--' : item.checkFa
}
})
this.tableData = list
}
},
到了这里,关于el-table数据处理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!