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

我希望勾选的时候父勾选,子节点都勾选,子节点取消勾选,父不变 #52

Closed
botshen opened this issue May 16, 2023 · 1 comment

Comments

@botshen
Copy link

botshen commented May 16, 2023

我尝试设置cascade,然后递归setchecked把子孙勾选,但是会慢,怎么解决这个问题,你的父子关联的时候父勾选,子孙也勾选就不会卡,是怎么实现的,不是递归吗

@ChuChencheng
Copy link
Collaborator

没看明白你的问题,不知道你是不是在尝试自己实现一个树组件?

  1. 如果父子节点是关联的,使用 setChecked 时会先判断其子节点是否都能勾选上,要考虑禁用、过滤之类的情况,然后再往上遍历其父节点,判断是半选状态还是全选状态,这个过程比较损耗性能,可能会卡。向下、向上遍历这两个过程都是递归的,具体可以参考 tree-store.ts
  2. 就标题的场景,不符合 cascade 这个 prop 的定义,目前组件是没有现成的实现。如果你把 cascade 设置为 false ,然后自己实现这种场景,我猜测卡顿的原因是每次 setChecked 执行过后,都会触发视图更新,导致重新渲染,所以节点多了就会卡顿。

针对第二点,目前组件暴露的 setChecked 方法是一定会触发视图更新的,我的建议是:

  1. 尝试使用 setData 方法,把勾选过后的数据重新设置一次,不使用 setChecked (之前没考虑过这种场景,我不确定是否实际可行)
  2. 自己维护一个版本,把 triggerDataChange 参数暴露出去

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

No branches or pull requests

2 participants