// An highlighted block
/**
* 树形数据搜索(广度优先遍历)
* @param {arr} tree
* @param {name} string
* @returns {obj}
*/
export function breadthSearch(tree, path) {
let stark = []
stark = stark.concat(tree)
while (stark.length) {
var temp = stark.shift()
if (temp.children) {
stark = stark.concat(temp.children)
}
if (temp.value === path) {
return temp
}
}
}
// 地址选择器回显
async echoAddress(provinceCode, cityCode, areaCode) {
if (provinceCode) {
// 省
await znArea({ code: 0 }).then(response => {
this.addressOptions = response.data.data.map(item => ({
value: item.code,
label: item.name,
leaf: false,
children: []
}))
})
// 市
await znArea({ code: provinceCode }).then(response => {
breadthSearch(this.addressOptions, provinceCode).children = response.data.data.map(item => ({
value: item.code,
label: item.name,
leaf: false,
children: []
}))
})
// 区
await znArea({ code: cityCode }).then(response => {
breadthSearch(this.addressOptions, cityCode).children = response.data.data.map(item => ({
value: item.code,
label: item.name,
leaf: true,
children: []
}))
})
return [[provinceCode, cityCode, areaCode], deepClone(this.addressOptions)]
} else {
return [[], []]
}
}
02-22
1063
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-28
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交