element多选级联回显

1.如果直接处理二维数据

// 转换后的二维数组(多选级联回显)
      convert(arr) {
        var map1 = {};
        while(arr.length) {
          let current = arr.pop(); // 会影响原数组
          // console.log('current.relationId',map1[current.relationId])
          map1[current.relationId] = map1[current.relationId] || [];
          if(current.tid){
            map1[current.relationId].push(current.tid, current.pid, current.relationId);
          }else{
            map1[current.relationId].push(current.pid,current.relationId);
          }
        }
        return Object.keys(map1).map(key => map1[key]);
      },
      

2.三维数据(先处理数据再调用convert()方法处理)

//多选级联回显(三级数据处理)
      // tid,1级数据;pid,2级数据;id,3级数据
      convertPlus(p){
        // console.log('ppp', p)
        const r = []
        const hash = {}
        const len = p.length
        for (let i = 0; i < len; i++) {
          hash[p[i]['relationId']] = p[i] //所有以id为标记的数据
        }
        console.log('hashVPforPid',hash)
        for (let j = 0; j < len; j++) {
          const aVal = p[j]
          const hashVP = hash[aVal['pid']] //取aVal以pid为标记的数据,如果在hash中存在
          if(hashVP){
            this.$set(aVal, 'tid', hashVP.pid)
          }
          r.push(aVal)
        }
        return r
      },

3.处理后的数据格式

页面效果(处理后台返回数据,回显效果如下):

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木易66丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值