本地 三级联动 适用于 element 三个 下拉框

本地三级联动 json资源 地址:
https://download.csdn.net/download/weixin_43138190/10812629       

 

getCityData: function() {
          var that = this
          axios.get(this.mapJson).then(function(response) {
            if (response.status == 200) {
              var data = response.data
              that.province = []
              that.city = []
              that.block = []
              // 省市区数据分类
              for (var item in data) {
                if (item.match(/0000$/)) { //省
                  that.province.push({
                    label: data[item],
                    item:item,
                    value: data[item],
                    children: []
                  })
                } else if (item.match(/00$/)) { //市
                  that.city.push({
                    label: data[item],
                    item:item,
                    value: data[item],
                    children: []
                  })
                } else { //区
                  that.block.push({
                    label: data[item],
                    item:item,
                    value: data[item]
                  })
                }
              }
              // 分类市级
              for (var index in that.province) {
                for (var index1 in that.city) {
                  if (that.province[index].item.slice(0, 2) === that.city[index1].item.slice(0, 2)) {
                    that.province[index].children.push(that.city[index1])
                  }
                }
              }
              // 分类区级
              for (var item1 in that.city) {
                for (var item2 in that.block) {
                  if (that.block[item2].item.slice(0, 4) === that.city[item1].item.slice(0, 4)) {
                    that.city[item1].children.push(that.block[item2])
                  }
                }
              }
            } else {
              console.log(response.status)
            }
          }).catch(function(error) {
            console.log(typeof + error)
          })
        },

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值