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

a-tree can't get halfCheckedKeys #4820

Closed
1 task
YunRan0526 opened this issue Oct 29, 2021 · 1 comment
Closed
1 task

a-tree can't get halfCheckedKeys #4820

YunRan0526 opened this issue Oct 29, 2021 · 1 comment

Comments

@YunRan0526
Copy link

YunRan0526 commented Oct 29, 2021

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

What problem does this feature solve?

衷心的希望能提供获取半选节点的api, 如果我不点击节点触发事件我就拿不到halfCheckedKeys。很多时候一个界面会有多个tree,在保持父子节点联动的特性的同时我需要在初始化后不操作a-tree组件 就可以直接获取halfCheckedKeys 。后端会将半选节点和全选节点的key一起返回给我,因此必须每次都手动分离。

What does the proposed API look like?

ant-design-vue:1.7.4
下面是我手动筛选节点的方法:贴上来只是想说自己有思考过,但是更期望有更好的解决办法。我自己也看了源码,无奈功力不够 有些无从下手。。。

//userData为一个含有 半选/全选节点 key的数组
function getAllKeys(treeData, userData) {
            let checkedKeys = [];
            let halfCheckedKeys = [];
            function testNode(node) {
                function isfullChecked(node) {
                    if (node?.children?.length) {
                        return node.children.every(res => userData.includes(res.key) && (res?.children?.length ? isfullChecked(res.children) : true));
                    }
                    return true
                }
                isfullChecked(node) ? checkedKeys.push(node.key) : halfCheckedKeys.push(node.key);
            }
            function divideNode(tree) {
                tree.forEach(node => {
                    if (userData.includes(node.key)) {
                        testNode(node);
                    }
                    if (node?.children?.length) {
                        divideNode(node.children)
                    }``
                })
            }
            divideNode(treeData);
            return {
                checkedKeys,
                halfCheckedKeys
            }
        }
@github-actions
Copy link

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 Oct 30, 2022
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

2 participants