function getParentId(list, code) {
for (const i in list) {
if (list[i].value === code) {
return [list[i].value]
}
if (list[i].children) {
const node = getParentId(list[i].children, code)
if (node !== undefined) {
return node.concat(list[i].value)
}
}
}
}
数据格式要是一下格式:
[
{
label:'测试1'
value:'1111'
children:[
{
label:'测试1'
value:'1111'
children:null
}
]
}
{
label:'测试1'
value:'1111'
children:[
{
label:'测试1'
value:'1111'
children:null
}
{
label:'测试1'
value:'1111'
children:[
label:'测试1'
value:'1111'
children:null
]
}
]
}
]