ant-design-vue 树型table,当子数组为[](空数组)而非null时,控制左侧展开按钮不显示
ant-design-vue 树型table,当子数组为[](空数组)而非null时,控制左侧展开按钮不显示
·
因为发现ant-design-vue组件库中的table组件,当数据源中的children属性为空数组[]时,在树型表格中该条数据没有子数据展开项,但是左侧展开按钮同样会显示,以下将解决这一问题,当数据源中的数据中的children属性为空数组 [] 时,控制左侧展开按钮不显示。
//只有实现该功能的必要代码,缺失属性请忽略
<template>
<a-table
children-column-name="childList"
row-key="id"
:expanded-row-keys="state.expandRowKeys"
>
<template #expandIcon="{ record }">
<template v-if="record.childList && record.childList.length === 0"
><span style="margin-right: 24px"></span //占位控制带有展开按钮的表格列缩进一致
></template>
<template v-else
><button
:class="[
'ant-table-row-expand-icon',
!state.isExpand[record.id]
? 'ant-table-row-expand-icon-collapsed' //使用组件库原展开按钮的样式
: 'ant-table-row-expand-icon-expanded'
]"
@click="expandRow(record.id)"
></button
></template>
</template>
</a-table>
</template>
<script>
import { reactive } from "vue"
const state = reactive({
expandRowKeys: [],
isExpand: {}
})
const expandRow = (id) => {
state.isExpand[id] = !state.isExpand[id];
if (!state.expandRowKeys.includes(id)) {
state.expandRowKeys.push(id);
} else {
const closedIndex = state.expandRowKeys.indexOf(id);
state.expandRowKeys.splice(closedIndex, 1);
}
};
</script>
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)