需要写一个方法,然后通过递归进行处理
1.表的列数据
{
title: '主要行业',
key: 'mainIndust',
width: 160,
render: (row: any) =>
(
<>
<div>
{recursionToGetLabel( 'msg', 'code', row.mainIndust, petitionContentTypeList.value )}
// 调用方法 参数分别是tree数据的label字段名,value字段名,后台返回的value值,tree的总数据
</div>
</>
)
},
2.方法如下:
function recursionToGetLabel( labelField: string, valueField: string, value: string | number, list: any[] ): string | undefined
{
for (let i = 0; i < list.length; i++)
{
if (list[i][valueField] === value) { return list[i][labelField] }
else if (list[i].children && list[i].children.length)
{ const temp = recursionToGetLabel(labelField, valueField, value, list[i].children) // 递归,最后一个参数为tree中的children数据
if (temp !== undefined)
{ return temp }
}
}
return undefined
}