UNPKG

react-antd-table-rowspan

Version:

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

38 lines (36 loc) 906 B
interface TreeDataFindItemParams { origin: any[] value: string childrenName?: string fieldName?: string } /** 通用的treeData递归查找某一项 * @origin 原始数据默认[] * @childrenName children字段名称默认children * @fieldName 对比的字段名称默认id * @value 需要对比的值默认为空字符串 */ function TreeDataFindItem({ origin = [], childrenName = 'children', fieldName = 'id', value = '', }: TreeDataFindItemParams) { let item = null function loop(arr: any[]) { for (let i = 0; i < arr.length; i++) { const x = arr[i] if (x[fieldName] === value) { item = x break } if (Array.isArray(x[childrenName]) && x[childrenName].length) { loop(x[childrenName]) } } } loop(origin) if (item) return item return null } export default TreeDataFindItem