根据树节点找到相应的路径

// 递归获取树子节点路径

getNodePath (treeData, nodeId, indexArray) {
                let arr = Array.from(indexArray)
                for (let i = 0, len = treeData.length; i < len; i++) {
                    arr.push(treeData[i].name)
                    if (treeData[i].id === nodeId) {
                        return arr;
                    }
                    let children = treeData[i].lists;
                    if (children && children.length) {
                        let result = this.getNodePath(children, nodeId, arr)
                        if (result) return result
                    }
                    arr.pop();
                }
                return false
            }

你可能感兴趣的:(根据树节点找到相应的路径)