js获取树行列表某个节点的父节点?-灵析社区

九久九

function findParentNode(list, cb, parent = null) { for(const node of list) { if(cb(node)) return parent; const res = findParentNode(node.children || [], cb, node); if(res) return res; } return null } findParentNode(arr, v => v.id === 2) // null findParentNode(arr, v => v.id === 311) // {id: 31 ...}

阅读量:1

点赞量:0

问AI