let adata = that.customTree(baseData, 'glid')
let shidata = that.getTreeItem(regioncode.toString(), adata, 'cityname')
ps: customTree构造树方法在前一篇文章中有介绍
adata 为树结构数据,regioncode为所需要查找的树节点的findId
js代码方法:
//构造树节点
getTreeItem(findId, array, findKey)
{
for (let index = 0; index < array.length; index++)
{
const element = array[index]
if (element[findKey] === findId)
return element
else if (element.children.length)
{
let result = this.getTreeItem(findId, element.children, findKey)
//在没有返回值的情况下才进行递归
if (result)
return result
}
}
return null
},
最终返回的所要查找的节点数据shidata