You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function getParentIds(id) {
let mapTree = {};
mapList(treeData)
function mapList(list) {
list.forEach(el => {
let key = el.orgId
mapTree[key] = el
if (el.children && el.children.length) {
mapList(el.children)
}
})
}
let cur = mapTree[id]
let parentId = cur && cur.parentId
let result = []
while (parentId) {
result.push(cur.parentId)
cur = mapTree[parentId]
parentId = cur.parentId
}
if(undefined != parentId){
result.push(parentId)
}
return result
}
`
第356天 根据元素ID遍历树形结构,查找到所有父元素ID [代码]
作者:hx8321
我也要出题
[{
"orgId": 1,
"orgName": "公室1",
"parentId": 0,
"children": [{
"orgId": 2,
"orgName": "公室2",
"parentId": 1,
"children": [{
"orgId": 3,
"orgName": "公室3",
"parentId": 2,
}]
}]
}]
描述:parentId:0表示已经到顶部了,这个树形结构层级可能是多层的
The text was updated successfully, but these errors were encountered: