vue elementui Cascader 级联选择器 省市区实现

<template>   <div style="width:300px;" >       <el-cascader         :options="options"         expand-trigger="hover"         @active-item-change="handleItemChange"         @change="handleChange"         :props="props"       style="width:530px;" ></el-cascader>   </div> </template> <script> import API from '@/api' export default {   name: 'area-select',   data () {     return {         options:\[\],         values:'',         texts:'',         props:{             value: 'id',             label:'name',             children: 'cities'         }     }   },   created () {         },   mounted(){     let page = this;      page.getCNodes('根',\[\]);   },   methods: {     getCNodes (parentid,currentIds) {         // console.log('加载下级节点')         let page = this;          let currentIdsSize = currentIds.length;         // console.log(currentIdsSize)         API.area.findChildren({             tyear:2016,             parentid:parentid         }).then(function (res) {             let cities = new Array();             res.forEach(function(r){                 if(r.depth < 5){                     cities.push({id:r.id,name:r.name,cities:\[\]});                 }else{                     cities.push({id:r.id,name:r.name});                 }                             });             if(currentIdsSize === 0){                 page.options = cities;             }else if(currentIdsSize === 1){                 page.options.forEach(function(r,index){                     if(r.id === currentIds\[0\]){                         page.options\[index\].cities = cities;                     }                 });             }else if(currentIdsSize === 2){                page.options.forEach(function(r0,i0){                     if(r0.id === currentIds\[0\]){                         page.options\[i0\].cities.forEach(function(r1,i1){                             if(r1.id === currentIds\[1\]){                                 page.options\[i0\].cities\[i1\].cities = cities;                             }                         });                     }                });             }else if(currentIdsSize === 3){                page.options.forEach(function(r0,i0){                     if(r0.id === currentIds\[0\]){                         page.options\[i0\].cities.forEach(function(r1,i1){                             if(r1.id === currentIds\[1\]){                                 page.options\[i0\].cities\[i1\].cities.forEach(function(r2,i2){                                     if(r2.id === currentIds\[2\]){                                         page.options\[i0\].cities\[i1\].cities\[i2\].cities = cities;                                     }                                 });                             }                         });                     }                });             } else if(currentIdsSize === 4){                page.options.forEach(function(r0,i0){                     if(r0.id === currentIds\[0\]){                         page.options\[i0\].cities.forEach(function(r1,i1){                             if(r1.id === currentIds\[1\]){                                 page.options\[i0\].cities\[i1\].cities.forEach(function(r2,i2){                                     if(r2.id === currentIds\[2\]){                                         page.options\[i0\].cities\[i1\].cities\[i2\].cities.forEach(function(r3,i3){                                             if(r3.id === currentIds\[3\]){                                                 page.options\[i0\].cities\[i1\].cities\[i2\].cities\[i3\].cities = cities;                                             }                                         });                                     }                                 });                             }                         });                     }                });             }                     })         .catch(function (error) {                      });       },     handleItemChange(val){       this.values = val;       // console.log(val)       let valSize = val.length;       let page = this;       if(valSize === 1){         //第2级节点获取         page.options.forEach(function(r,index){             if(r.id === val\[0\]){                 page.getCNodes(r.id,val);                 return;             }         });       }       if(valSize === 2){         //第3级节点获取         page.options.forEach(function(r,index){             if(r.id === val\[0\]){                 r.cities.forEach(function(r0,i0){                     if(r0.id === val\[1\]){                         page.getCNodes(r0.id,val);                         return;                     }                 });             }         });       }       if(valSize === 3){         //第4级节点获取         page.options.forEach(function(r0,i0){             if(r0.id === val\[0\]){                 r0.cities.forEach(function(r1,i1){                     if(r1.id === val\[1\]){                         r1.cities.forEach(function(r2,i2){                             if(r2.id === val\[2\]){                                 page.getCNodes(r2.id,val);                                 return;                             }                         });                      }                 });             }         });       }       if(valSize === 4){         //第5级节点获取         page.options.forEach(function(r0,i0){             if(r0.id === val\[0\]){                 r0.cities.forEach(function(r1,i1){                     if(r1.id === val\[1\]){                         r1.cities.forEach(function(r2,i2){                             if(r2.id === val\[2\]){                                 r2.cities.forEach(function(r3,i3){                                     if(r3.id === val\[3\]){                                         page.getCNodes(r3.id,val);                                         return;                                     }                                 });                             }                         });                      }                 });             }         });       }     },     handleChange (v){         let page = this;         page.options.forEach(function(r0,i0){             if(r0.id === v\[0\]){                 page.values = r0.id;                 page.texts = r0.name;                 r0.cities.forEach(function(r1,i1){                     if(r1.id === v\[1\]){                         page.values += ','+r1.id;                         page.texts += ','+r1.name;                         r1.cities.forEach(function(r2,i2){                             if(r2.id === v\[2\]){                                 page.values += ','+r2.id;                                 page.texts += ','+r2.name;                                 r2.cities.forEach(function(r3,i3){                                     if(r3.id === v\[3\]){                                         page.values += ','+r3.id;                                         page.texts += ','+r3.name;                                         r3.cities.forEach(function(r4,i4){                                             if(r4.id === v\[4\]){                                                 page.values += ','+r4.id;                                                 page.texts += ','+r4.name;                                             }                                         });                                     }                                 });                             }                         });                     }                 });             }         });     }   } } </script>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

KVM调整cpu和内存

一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid