antd table动态表头_React项目使用ant Table组件动态生成columns

在React项目中,使用Ant Design的Table组件时,常常需要根据后台返回的数据动态生成columns配置。本文介绍如何根据`schemasMessage`数据结构,生成如`columns`所示的动态表头。具体实现涉及递归遍历数据,构建嵌套的columns对象,以展示复杂层级的表格数据。

1.描述:公司做一个后台项目,需要渲染列表,我是用的是ant的Table组件,但是要求根据数据动态生成columns,请问有什么方法可以把一下类似的数据动态生成对应的columns吗?

2.数据结构:const schemasMessage = [

{

"code": "011234567890",

"generalInfo": {

"name": "xx有限公司",

"shortName": "xx",

"taxPayerType": "xx",

"taxPayerTypeId": "1",

"registeredCapital": 500,

"characterOfEconomy": "xxx",

"characterOfEconomyId": "21"

},

"transaction": {

"bankName": "xx",

"bankAccount": "1234567890",

"bankLocation": {

"province": "xx",

"city": xx",

}

},

"location": {

"province": "北京",

"city": "北京",

"district": "海淀区",

"street": "xx",

"address": "xx",

"postCode": "01000000"

},

"contacts": [

{

"name": "xx",

"position": "xx"

},

{

"name": "xx",

"position": "xx"

}

],

"marketing": {}

}]

const columns = [

{title:'Code',dataIndex: 'code',key:'code',fixed: 'left'},

{title: 'GeneralInfo',

children:[

{title:'Name',dataIndex: 'name',key:'name'},

{title:'shortName',dataIndex: 'shortName',key:'shortName'},

]

}, {

title: 'Transaction',

children: [{

title: 'bankName',

dataIndex: 'bankName',

key: 'bankName',

},

{ title: 'bankAccount',

dataIndex: 'bankAccount',

key: 'bankAccount',},

{

title: 'bankLocation',

children: [{

title: 'province',

dataIndex: 'province',

key: 'province',

}, {

title: 'city',

dataIndex: 'city',

key: 'city',

}],

}],

},

{

title: 'contacts',

children: [{

title: 'contacts1',

children:[

{title: 'Name',

dataIndex: 'name',

key: 'name',},

{title: 'position',

dataIndex: 'position',

key: 'position',},

]

},{

title: 'contacts2',

children:[

{title: 'Name',

dataIndex: 'name',

key: 'name',},

{title: 'position',

dataIndex: 'position',

key: 'position',},

]

}],

}];

请问如何实现?

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值