vue3 Select 下拉选择器 数据格式改成自定义key

Select选择器​​​​​​官网地址

当前数据格式改成格式

[

{
id: 'id',
pid: 'pid', //可能多个0
name: 'name',
code: 'code', /
}

...

]

[ {
code: 'code',
label: 'label',
children: 'children',
}

.....

]

<template>
    <vxe-column field="relationShipName" title="关系" align="center" min-width="120">
        <template #default="{ row }">
            <el-tree-select
            v-model="row.relationShip"
            :props="props"
            filterable
            value-key="code"
            node-key="code"
            :data="relationShipTreeData"
            :render-after-expand="false"
            @change="checkGx(row)"
                  />
            </template>
        </vxe-column>
</template>
<script setup>
    const props = {
      //value: 'id',
      code: 'code',
      label: 'label',
      children: 'children',
    }
    //点击事件
    const clearHz = (row) => {
      
    }

    //获取字典数据--转化成select标准格式
    const getDictionary = () => {
      proxy.$api.a.b.dictionary('relationShip')
          .then(res =>{
            state.relationShipTreeData = transformToTree(res.data.data);
          })
          .catch(err => {})
    }

    // 转换函数
    const transformToTree = (arr) =>{
      let map = {}, node, roots = [], i;
      for (i = 0; i < arr.length; i += 1) {
        map[arr[i].id] = i;
        arr[i].code = arr[i].code;
        arr[i].label = arr[i].name;
        arr[i].children = [];
      }
      for (i = 0; i < arr.length; i += 1) {
        node = arr[i];
        if (node.pid !== 0) {
          arr[map[node.pid]].children.push(node);
        } else {
          roots.push(node);
        }
      }
      return roots;
    }
</script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值