UNPKG

react-antd-table-rowspan

Version:

react+antd表格指定的列,连续的,行合并

38 lines (37 loc) 1.09 kB
interface TreeDataFindParentParams { /** 原始数据 */ origin: any[] /** 要查找对比的值 */ value: string | number /** 要查找对比的字段名称,默认是id */ fieldName?: string /** 需要返回的是什么字段,默认取fieldName */ needFieldName?: string /** children字段名称,默认是children */ childrenName?: string } /** TreeData查找所有父级 */ function TreeDataFindParent({ origin = [], fieldName = 'id', childrenName = 'children', value = '', needFieldName = fieldName, }: TreeDataFindParentParams) { let temp: any[] = [] function loop(arr: any[], value: string | number) { arr.forEach((x: any) => { if (Array.isArray(x[childrenName]) && x[childrenName].length) { if (x[childrenName].map((y: any) => y[fieldName]).includes(value)) { temp.push(x[needFieldName]) loop(origin, x[fieldName]) } else { loop(x[childrenName], value) } } }) } loop(origin, value) return temp } export default TreeDataFindParent