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

n-tree 初始化设置default-checked-keys后,不会触发@update:checked-keys和@update:indeterminate-keys #3837

Closed
laterdays opened this issue Oct 10, 2022 · 17 comments
Labels
feature request New feature or request

Comments

@laterdays
Copy link

TuSimple/naive-ui version (版本)

2.33.4

Vue version (Vue 版本)

3.2.40

Browser and its version (浏览器及其版本)

chrome

System and its version (系统及其版本)

windows

Node version (Node 版本)

Reappearance link (重现链接)

https://codesandbox.io/s/r0c7vg?file=/src/Demo.vue

Reappearance steps (重现步骤)

n-tree 初始化设置default-checked-keys后,不会触发@update:checked-keys和@update:indeterminate-keys

Expected results (期望的结果)

当我初始化default-checked-keys的时候, 如果不手动点击一下复选框,不会触发@update:checked-keys和@update:indeterminate-keys,则无法拿到indeterminate半选的数据

是否可以像elementplus一样提供
getHalfCheckedKeys
getCheckedKeys
等方法来解决这个场景

Actual results (实际的结果)

n-tree 初始化设置default-checked-keys后,不会触发@update:checked-keys和@update:indeterminate-keys

Remarks (补充说明)

@github-actions github-actions bot added the untriaged need to sort label Oct 10, 2022
@laterdays
Copy link
Author

laterdays commented Oct 10, 2022

一个场景是:后台只给了6个全选的数据,这样给到ne-tree的时候, 会有半选的节点被勾选上,现在可能6个全选 + 2个半选的节点,此时我保存数据给后台的话, 按照现有的逻辑就拿不到另外两个半选节点的数据

@laterdays
Copy link
Author

@07akioni 这在现在的系统中很重要, 希望可以考虑满足这种场景。不然设置过全选数据后,不勾选一下复选框 就无法触发@update:checked-keys和@update:indeterminate-keys回调,,无法再拿到相关的半选数据。

@laterdays
Copy link
Author

1665411655132
是否可以提供类似的函数

@lx11573
Copy link

lx11573 commented Oct 11, 2022

官方的组件都是受控和非受控, 所以 default- 的应该都是非受控的, 如果需要使用受控 checked 的话,直接使用 checked-keys 就可以, 而且 on-update:checked-keys 很明显和 checked-keys 是一对, indeterminate-keys 也有对应的 onUpdate

@laterdays
Copy link
Author

如果数据全是全选数据,使用checked-keys, 此时会有对应被勾选的半选数据,但如果不触发回调,是拿不到对应被勾选的半选数据,

@lx11573
Copy link

lx11573 commented Oct 11, 2022

如果数据全是全选数据,使用checked-keys, 此时会有对应被勾选的半选数据,但如果不触发回调,是拿不到对应被勾选的半选数据,

on-update:indeterminate-keys 可以拿到的半选的
如果数据存在全选和半选的话,就要用到 on-update:indeterminate-keyson-update:checed-keys

@lx11573
Copy link

lx11573 commented Oct 11, 2022

如果数据全是全选数据,使用checked-keys, 此时会有对应被勾选的半选数据,但如果不触发回调,是拿不到对应被勾选的半选数据,

on-update:indeterminate-keys 可以拿到的半选的 如果数据存在全选和半选的话,就要用到 on-update:indeterminate-keyson-update:checed-keys

同时需要 cascade: true

@laterdays
Copy link
Author

场景是:你初始化默认给checked-keys赋值(里面是全选的数据), 此时不进行任何操作,应该是拿不到对应半选的数据吧 ?

@laterdays
Copy link
Author

laterdays commented Oct 11, 2022

只有勾选了,触发了(on-update:indeterminate-keys) 回调,才可以拿到, 如果初始化之后,不进行勾选操作,但此时Tree中已经有了关联的半选数据,就拿不到了。

@lx11573
Copy link

lx11573 commented Oct 11, 2022

只有勾选了,触发了(on-update:indeterminate-keys) 回调,才可以拿到, 如果初始化之后,不进行勾选操作,但此时Tree中已经有了关联的半选数据,就拿不到了。

这个确实

@laterdays
Copy link
Author

所以之前也有issue提到有种场景是这样的,初始化给全选数据, 但是现在Tree对应的也有半选, 然后我什么也不勾选,我现在提交给后台,想把半选的一起给, 就没有办法能解决

@laterdays
Copy link
Author

图片
估计element plus 给这些方法, 也是为了解决类似的问题

@07akioni
Copy link
Collaborator

07akioni commented Oct 11, 2022

这些方法会考虑尽快加上,我理解确实用户需要

@07akioni
Copy link
Collaborator

至于不触发显然是个正确的行为,解决方式还得是加方法

@07akioni 07akioni added feature request New feature or request and removed untriaged need to sort labels Oct 11, 2022
@laterdays
Copy link
Author

@07akioni 非常感谢,初始化不触发是可以的,希望能尽快提供些方法,目前导致整个系统的Tree无法正常回显和二次编辑, 感谢

@iBoot4j
Copy link

iBoot4j commented Oct 15, 2022

@07akioni 类似问题,mark!!!设置了checed-keys之后,整个树的checkbox无法点击。

@07akioni
Copy link
Collaborator

@07akioni 非常感谢,初始化不触发是可以的,希望能尽快提供些方法,目前导致整个系统的Tree无法正常回显和二次编辑, 感谢

it will be added in the next version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants
@lx11573 @07akioni @iBoot4j @laterdays and others