el-cascader的点击第二次才被选中 以及 回显问题

// 取消使用v-model绑定值  用ref来获取值
<el-cascader :options="depOptions" ref='countrySelectRef' clearable @change='depChange()'></el-cascader>

 depChange() {
 	// 获取的是选中的value
     this.$refs["countrySelectRef"].getCheckedNodes()[0].path;
     //获取的是选中的值的label
     this.$refs["countrySelectRef"].getCheckedNodes()[0].pathLabels
},

//还有一种方法
<el-cascader model-value="AddDateModel.departme" :options="depOptions" clearable @change='depChange()'></el-cascader>

**// 前两种方法,回显都有问题,这是第三种;用value,回显的时候把值给了value就好了。**
<el-cascader :value="depValue" :options="depOptions" ref='countrySelectRef' clearable @change='depChange'></el-cascader>
// 回显
this.AddDateModel.departme = this.getPidMenuList('选中的值');
//方法
getPidMenuList(pid) {
   let cid_list = [];
   this.depOptions.forEach((item, index) => {
       if (item.value == pid) {
           cid_list = [item.value];
           return false;
       } else {
           if (item.children) {
               let newCid_list = [item.value];
               let list = nodefun(item.children, pid, newCid_list);
               if (list) {
                   cid_list = list;
               }
           }
       }
   });
   // 递归函数
   function nodefun(newVal, newId, newCid_list) {
       let flag = false;
       newVal.forEach((j) => {
           if (j.value == newId) {
               newCid_list.push(j.value);
               flag = true;
           } else {
               if (j.children) {
                   let cid_list = JSON.parse(
                       JSON.stringify(newCid_list)
                   );
                   cid_list.push(j.value);
                   let list = nodefun(j.children, newId, cid_list);
                   if (list) {
                       newCid_list = list;
                       flag = true;
                   }
               }
           }
       });
       if (flag) {
           return newCid_list;
       }
   }
   return cid_list;
},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值