遍历json数据

遍历json数据

var city=[
  {
    value: 1, label: '北京', childrens: [
      {
        value: 1, label: '北京市', childrens: [
          { value: 1, label: '东城区' },
          { value: 2, label: '西城区' },
          { value: 3, label: '崇文区' },
          { value: 4, label: '宣武区' },
          { value: 5, label: '朝阳区' },
          { value: 6, label: '丰台区' },
          { value: 7, label: '石景山区' },
          { value: 8, label: '海淀区' },
          { value: 9, label: '门头沟区' },
          { value: 10, label: '房山区',
            childrens: [
              {
                label: '长沟镇'
              }
            ]
          },
          { value: 11, label: '通州区' },
          { value: 12, label: '顺义区' },
          { value: 13, label: '昌平区' },
          { value: 14, label: '大兴区' },
          { value: 15, label: '怀柔区' },
          { value: 16, label: '平谷区' },
          { value: 17, label: '密云县' },
          { value: 18, label: '延庆县' }
        ]
      }
    ]
  }
]

var area = city[0].childrens[0].childrens;
for (var i = 0; i <area.length;i++){
  if (area[i].childrens){
    console.log('含有乡镇:' + area[i].childrens[0].label)
  }
}

遍历json数据筛选到城镇

来都来了,留个言吧🙂