当前数据格式 | 改成格式 |
[ { ... ] | [ { ..... ] |
<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>