当前位置: 首页 > news >正文

antd-tree的半选回显,不联动父类节点,非严格模式下也可以

出现的问题,树节点在非严格模式下,如果回显,会自动选中父节点以下的所有节点

在这里插入图片描述

方案1 在请求回来前设置 check-strictly 为true,请求完成后,设置为 false,没生效

方案2 在请求回来回显的接口时,取没有children的项,进行设置回显,在切换选中时,将半选的也设置上

 <a-treeref="aTreeRef"v-model:checkedKeys="checkedKeys" default-expand-all checkable :field-names="fieldNames":tree-data="treeData"@check="onCheck"/>

回显

function findRoleMenuByRoleIdFn() {findRoleMenuByRoleId({roleId: props.editRoleObj.roleId,}).then((res: any) => {if (res.code === '0000') {checkedKeys.value = getOnlychildrenIds(res.data, [])menuIds.value = getAllAllIds(res.data, [])}})
}
// 半选的情况下,也传父节点
function onCheck(_keys: any, e: any) {const arr = _keys.concat(e.halfCheckedKeys)menuIds.value = [...arr]
};function getAllAllIds(tree: any, result: any = []) {// 遍历树  获取id数组for (const i in tree) {result.push(tree[i].menuId) // 遍历项目满足条件后的操作if (tree[i].children) {// 存在子节点就递归getAllAllIds(tree[i].children, result)}}return result
}
// 回显的时候,默认值只取子项的id
function getOnlychildrenIds(tree: any, result: any = []) {// 遍历树  获取id数组for (const i in tree) {if (tree[i].children.length <= 0) {console.log(tree[i].menuId)result.push(tree[i].menuId) // 遍历项目满足条件后的操作}else {getOnlychildrenIds(tree[i].children, result)}}return result
}

取到的 menuIds就是最终选中的值,只是回显的时候,使用了另一个变量进行设置

在这里插入图片描述


http://www.mrgr.cn/news/45362.html

相关文章:

  • vector 的使用详解
  • 如何使用 vSphere Client 给虚拟机扩容
  • LeetCode-12. 整数转罗马数字【哈希表 数学 字符串】
  • 双向链表基本操作实现--建议做题时画图 切不可死记
  • qiankun(乾坤)解决父子应用样式的影响和策略
  • ②EtherNet/IP转ModbusTCP, EtherCAT/Ethernet/IP/Profinet/ModbusTCP协议互转工业串口网关
  • 2024下半年国内EI学术会议有哪些
  • 数据库SQL 某字段按首字母排序_sql按首字母排序
  • unix系统中的system函数
  • Spring Cloud微服务详解
  • EDA脚本应用领域及使用特点
  • 实战千问2大模型第四天——Qwen2-VL-7B(多模态)lora微调训练和测试
  • python画图|显式和隐式接口The explicit and the implicit interfaces
  • can 总线入门———can简介硬件电路
  • Redis面试篇1
  • 也来猜猜 o1 实现方法
  • OpenCV高级图形用户界面(3)关闭由 OpenCV 创建的指定窗口函数destroyWindow()的使用
  • PCL-点云质心识别
  • 机器学习——强化学习与深度强化学习
  • JioNLP:一款实用的中文NLP预处理工具包