Skip to content

怎么修改某个节点的数据 #85

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 Feb 22, 2024 · 1 comment · Fixed by #102
Closed

怎么修改某个节点的数据 #85

xtuer opened this issue Feb 22, 2024 · 1 comment · Fixed by #102

Comments

@xtuer
Copy link

xtuer commented Feb 22, 2024

问题描述
使用 setData 设置数据 (非响应式的方式,没有使用 :data 进行双向绑定),怎么修改某个节点的数据例如 title,然后树上此节点马上更新看到效果呢?

需求来源,例如重命名树的节点。

组件版本

  • Vue3
  • @wsfe/vue-tree ^3.2.0
@ChuChencheng
Copy link
Collaborator

我有两个想法

  1. setData 目前执行之前会把树的 scrollTop 重置为 0 ,以防止新的数据与旧的数量不一致(更少)导致白屏问题。可以给 setData 加一个选项,不重置 scrollTop 。不过这要用户自己保证传入新的 data 数量要与旧的保持一致
  2. 加一个 API 更新 title ,比如 setNodeTitle(key: string, newTitle: string)

第一个方案比较类似 React setState 了,不过用起来会比较繁琐,要自己去找到节点

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

Successfully merging a pull request may close this issue.

2 participants