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

fix(tree): 修复编辑模式下保存无效问题 (#3017) #3018

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

zyprepare
Copy link
Collaborator

@zyprepare zyprepare commented Oct 11, 2024

closed #3017
closed #3022

问题:
拖拽后再去编辑,节点又被重置到之前的位置,原因是通过 useTreeAction 生成的 ActionTree 组件中使用的 data 和 Tree 组件中的 data 数据状态不一致。

解决方案:
遇到该场景,可以在 onDragEnd 回调中拿到第三个参数(更新后的 treeData),去更新 data,示例代码如下:
`export const Editable = () => {
const ActionTree = useTreeAction(Tree)
const [data, setData] = React.useState([])

return (
<ActionTree
expandOnSelect
editPlaceholder="请填写菜单"
menuOptions={[]}
data={data}
onDragEnd={(evt, options, treeData) => {
setData(treeData)
}}
/>
)
}`

@zyprepare zyprepare merged commit 1e382ae into master Oct 17, 2024
1 check passed
@zyprepare zyprepare deleted the hotfix/tree/3017 branch October 17, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tree 拖拽和编辑模式下保存时异常 Tree 编辑模式下保存无效
1 participant