共计 383 个字符,预计需要花费 1 分钟才能阅读完成。
//utils.js
export const checkList = (list, code, path = []) => {if (!list) return []
for (const data of list) {path.push(data.value)
if (data.value == code) return path
if (data.children && data.children.length) {const findchildren = checkList(data.children, code, path)
if (findchildren.length) return findchildren
}
path.pop()}
return []}
引入应用
import {checkList} from '../utils/utils.js'
let arr = checkList(list , code).filter(Boolean)
正文完
发表至: javascript
2021-11-19