/*
* getTreeIds() 递归当前点击的树层级下的所有regionId
* unique() 数组去重(可调用也可不调用)
* */
getTreeIds(data) {
if (data.children instanceof Array) {
data.children.forEach(item => {
this.regionIdList.push(item.regionId)
this.getTreeIds(item)
})
}
this.unique(this.regionIdList)
},
unique(arr) {
return Array.from(new Set(arr))
}
this.regionIdList.push(data.regionId)
this.getTreeIds(data)
另:每次点击树节点时清空regionIdList 数组
本文介绍了一种通过递归函数获取多级树形结构中所有节点ID的方法,并实现了一个数组去重的功能。该方法适用于处理具有层级关系的数据集,如地区划分等。
5798

被折叠的 条评论
为什么被折叠?



