省市县筛选某个城市

//示例数据
[{
  value: '510000',
  text: '四川省',
  children: [{
    value: "510100",
    text: "成都市",
    children: [{
      value: "510104",
      text: "锦江区"
    }, {
      value: "510105",
      text: "青羊区"
    }, {
      value: "510106",
      text: "金牛区"
    }]
  },{
    value: "510300",
    text: "自贡市",
    children: [{
      value: "510302",
      text: "自流井区"
    }, {
      value: "510303",
      text: "贡井区"
    }]
  }]
}]

//处理数据
findList(arr, val) {
  let res = null
  for (let i = 0; i < arr.length; i++) {
    if (arr[i].value === val) {
      res = arr[i].text
      return arr[i].text
    }
    else if (arr[i].children && arr[i].children.length > 0) {
      res = this.findList(arr[i].children, val)
    }
    if (res) break
  }
  return res
},


let text = findList(cityData, '510106')
console.log(text)

MRZYD
145 声望10 粉丝

一个初学的小菜鸟,望各位大佬多多指教