企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
>[info] Tree转数组 ~~~ /** * @description 树转数组,队列实现广度优先遍历 * @param {Array} data 数据 * @param {Object} props `{ children: 'children' }` */ export const treeToArray = (data: any[], props = { children: 'children' }) => { data = cloneDeep(data) const { children } = props const newData = [] const queue: any[] = [] data.forEach((child: any) => queue.push(child)) while (queue.length) { const item: any = queue.shift() if (item[children]) { item[children].forEach((child: any) => queue.push(child)) delete item[children] } newData.push(item) } return newData } ~~~