Skip to content

怎么只更新某一个节点的样式? #61

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

Closed
xtuer opened this issue Jul 24, 2023 · 4 comments
Closed

怎么只更新某一个节点的样式? #61

xtuer opened this issue Jul 24, 2023 · 4 comments

Comments

@xtuer
Copy link

xtuer commented Jul 24, 2023

使用 setData() 的方式设置树的数据 (使用非响应式):

  1. 节点 node 当前是非叶子节点,其 node.isLeaf 为 false,有小三角形箭头。
  2. 手动修改 node.isLeaf = true 把节点修改为叶子节点,节点的样式没有变,即小三角形箭头还在。
  3. 调用树的方法 tree.value.clearChecked() 强制更新整棵树,这时 node 的小三角形箭头消失。

有没有更好的方法,只更新某个节点的样式?

@ChuChencheng
Copy link
Collaborator

如果你要把非叶子节点变成叶子节点,把它底下的所有子节点都删除可以吗,调用 remove 方法
或者在数据中把子节点都去掉,重新 setData 试试

@xtuer
Copy link
Author

xtuer commented Jul 25, 2023

如果你要把非叶子节点变成叶子节点,把它底下的所有子节点都删除可以吗,调用 remove 方法
或者在数据中把子节点都去掉,重新 setData 试试

谢谢回复,其实这只是一个例子,因为还有不少情况需要更新某个指定节点的样式,例如修改某个属性值,节点的样式要更新。

@xtuer
Copy link
Author

xtuer commented Feb 22, 2024

节点数据变化了,调用 tree.value.clearChecked() 强制更新节点样式。

^3.1.0 的时候 tree.value.clearChecked() 这个方法还能勉强实现这个功能,但是 ^3.2.0 后这个功能失效了。

问题: 有没有办法在修改节点的数据 node.title = 'foo' 后,更新这个节点呢?

@ChuChencheng
Copy link
Collaborator

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