Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree select 组件的参数 showCheckedStrategy 值不起作用,选择SHOW_ALL还是显示子节点 #2113

Closed
1 task done
glxe opened this issue Apr 18, 2020 · 21 comments
Closed
1 task done

Comments

@glxe
Copy link

glxe commented Apr 18, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

1.4.11

Environment

mac chrome vue2.6.11

Reproduction link

Edit on CodeSandbox

Steps to reproduce

使用tree select 组件来选择地区,但是参数 showCheckedStrategy 值不起作用,选择SHOW_ALL还是只显示子节点

What is expected?

showCheckedStrategy 选择对应的值却无效果

What is actually happening?

showCheckedStrategy 选择对应的值却无效果

@jzyzxx
Copy link

jzyzxx commented Aug 5, 2020

我也遇到同样的问题

@glxe
Copy link
Author

glxe commented Aug 6, 2020

@jzyzxx 一直在等待回复呢

@xrkffgg
Copy link
Member

xrkffgg commented Aug 6, 2020

https://antdv.com/components/tree-select-cn/#components-tree-select-demo-checkable

仔细看一下这个 🌰

@laura233
Copy link

我也遇到了同样的问题

@laura233
Copy link

laura233 commented Aug 26, 2020

@xrkffgg https://antdv.com/components/tree-select-cn/#components-tree-select-demo-checkable 这里没有showCheckedStrategy使用的demo,设置showCheckedStrategy="SHOW_ALL"还是只显示子节点

@xrkffgg
Copy link
Member

xrkffgg commented Aug 26, 2020

image

@laura233
Copy link

laura233 commented Aug 26, 2020

<a-tree-select v-model="value" style="width: 100%" :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }" :tree-data="regionTree" @select="handleSelect" :show-checked-strategy="SHOW_ALL" placeholder="选择区域" tree-default-expand-all >

import { TreeSelect } from 'ant-design-vue';
const SHOW_ALL = TreeSelect.SHOW_ALL;

data: function () { return { regionTree: [], SHOW_ALL } },

这样还是只显示子节点,请问还有什么地方有问题吗 @xrkffgg

@xrkffgg
Copy link
Member

xrkffgg commented Aug 26, 2020

你用这个提供一个复现 https://codesandbox.io/s/vue-antd-template-5z9pl?file=/src/App.vue 我看看

@laura233
Copy link

您提供的demo已经是SHOW_ALL了,右边的下拉框不也是没展示父节点吗

@xrkffgg
Copy link
Member

xrkffgg commented Aug 26, 2020

我是用的楼主的链接。其实这个 show-checked-strategy 是需要 tree-checkable 的。

@laura233
Copy link

好吧,我加tree-checkable试了下,展示的是当前选中节点及其下面所有的子节点,并不是选中节点及其父节点

@glxe
Copy link
Author

glxe commented Aug 27, 2020

这个玩意我试过很多次,可是并没有得要想要的结果。还是说这个SHOW_ALL本来就是这个效果呢?不是我们所理解的呢。

@buqiyuan
Copy link
Member

image

 // 选择节点
    const treeSelect = (value,node,extra) => {
      let currentNode = extra.triggerNode
      let str = ''
      while (currentNode.dataRef.pId != 0) {
        str += currentNode.title + ' / '
        currentNode = currentNode.vcTreeNode
      }
      str += currentNode.title
      treeSelectRef.value.$el.parentElement.querySelector('.ant-select-selection-selected-value').textContent = str.split(' / ').reverse().join(' / ')
    }

自己动手丰衣足食

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@Mfweb
Copy link

Mfweb commented Jun 9, 2021

至今未解决

@jinxinkai
Copy link

至今未解决 +1

1 similar comment
@zhuman90
Copy link

至今未解决 +1

@948489458
Copy link

treeSelectRef

是什么

@williamwang2013
Copy link

williamwang2013 commented Jan 13, 2022

我的问题类似,我已通过后台方式处理解决。
我的环境是react+ ant design 3.26.7,要实现给菜单树赋权的效果,用treeselect ,
<TreeSelect
style={{ width: '100%' }}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
treeData={roleTreeList}
treeCheckable="true"
showCheckedStrategy={SHOW_ALL}
placeholder="请设置菜单权限"
onChange={onTreeChange}
/>,
假设某个1级菜单目录-系统管理下,有3个子菜单,用户管理、角色管理、菜单管理,用treeselect赋权时,我只选了用户管理和角色管理2个子菜单,实际上的treeselect values中应该要包含父级菜单系统管理的id的,但是因为系统管理下的3个子菜单没有全部选中,即使 showCheckedStrategy={SHOW_ALL},在获取treeselect value时是拿不到系统管理的key值的。
我通过后台来解决的,我的解决方式如下:
1.前台没办法通过组件来拿到系统管理的key值,前台传值不变
2.后台拿到前台传过来的所有key值,递归查找所有父节点后,跟前台传值做并集后做唯一值筛选。这样保证可以拿到所有前台漏掉的父节点值。入库时的数据不会有问题
3.这样会导致一个新问题出现,就是由于系统管理父节点的值入库了,在treeselect上明明应该是只显示系统管理和用户管理、角色管理两个子菜单的,但是如果从库里面拿数据的话,系统管理的key默认也是选中的,会变成了系统管理下的3个子菜单都是选中的状态
4. 第3步中的问题我是这么处理的,数据库中存入了系统管理的节点id,但是在treeselect绑定values值时,过滤掉这些父节点的key值,具体sql类似如下,我这里是角色赋权,在角色创建时指定角色有权限操作的菜单树。角色表上加一个字段menuCheckStrictly,默认为true。然后入库时父节点key值即使入库,再取数据库值绑定到treeselect时,由于角色menuCheckStrictly为true,会过滤掉这些父节点key值。

    select m.menu_id
	from sys_menu m
        left join sys_role_menu rm on m.menu_id = rm.menu_id
    where rm.role_id = #{roleId}
        <if test="menuCheckStrictly">
          and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id = rm.menu_id and rm.role_id = #{roleId})
        </if>
	order by m.parent_id, m.order_num
 整个操作,已经测试成功,基本达到我的要求。

@huifang-jiang
Copy link

huifang-jiang commented Mar 3, 2022

可设置treeNodeLabelProp属性

<template>
    <a-tree-select  :tree-data="treeData"  treeNodeLabelProp="fullTitle" />
</template>
<script>
export default {
     setup() {
         return {
              treeData: [
                   {
                      value: '1',
                      title: '1月',
                      fullTitle: '1月',
                      children: [
                         {
                            value: '1-1',
                            title: '1号',
                            fullTitle: '1月 / 1号',   // key值可自定义,内容自行拼接,选中框将展示此条数据
                         },
                         {
                            value: '1-1',
                            title: '2号',
                            fullTitle: '1月 / 2号',
                         }
                     ]
                  }
              ]
         }
     }
}
</script>

@github-actions
Copy link

github-actions bot commented Mar 4, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests