1234567891011121314151617181920212223242526272829303132 |
- import { TypeZ1dict } from './type'
- // 把所有的字典,只保留前面2级,给下拉框筛选
- export const Z1toTowFu = (data: TypeZ1dict[]) => {
- return data.map(item => ({
- ...item,
- children: item.children?.map(child => ({
- ...child,
- children: undefined // 移除第三层子级
- }))
- }))
- }
- // 通过id获取 树的obj
- export const treeResIdFu = (list: any, id: string) => {
- // 每次进来使用find遍历一次
- let res = list.find((item: any) => item.id === id)
- if (res) {
- return res
- } else {
- for (let i = 0; i < list.length; i++) {
- if (list[i].children instanceof Array && list[i].children.length > 0) {
- res = treeResIdFu(list[i].children, id)
- if (res) return res
- }
- }
- return null
- }
- }
|