graph.batchUpdate能合并node.setData方法吗
问题描述
代码
graph.batchUpdate(() => {
if (selectedList.length === 0) {
nodes.forEach(el => {
const node = graph?.getNodes().find(e => e.id === el.id)
if (node?.data?.selected) {
node?.setData({ ...el.data, selected: false })
}
})
} else {
selectedList.forEach(el => {
const node = graph?.getNodes().find(e => e.id === el.id)
if (!node?.data?.selected) {
node.setData({ ...el.data, selected: true })
}
})
}
})
目前使用graph.batchUpdate并不能将node.setData方法合并;我并不清楚这是x6本身不支持还是一个bug
重现链接
无
重现步骤
// 合并代码 graph.batchUpdate(() => { if (selectedList.length === 0) { nodes.forEach(el => { const node = graph?.getNodes().find(e => e.id === el.id) if (node?.data?.selected) { node?.setData({ ...el.data, selected: false }) } }) } else { selectedList.forEach(el => { const node = graph?.getNodes().find(e => e.id === el.id) if (!node?.data?.selected) { node.setData({ ...el.data, selected: true }) } }) } }) // 撤销 graph.undo() // 查看nodes的data属性是否全部都撤回了 graph.getNodes()
预期行为
我希望是会合并成一个操作,但是并没有
平台
- 操作系统: [macOS, Windows, Linux, React Native ...]
- 网页浏览器: [Google Chrome, Safari, Firefox ...]
- X6 版本: [2.11.1 ...]
屏幕截图或视频(可选)
No response
补充说明(可选)
No response
👋 @jackol47
Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
搞一个demo看看
是的,我也遇到了同样的问题,我用setData设置节点的数据,并希望通过History插件进行撤销和重做动作,但是发现并不行,然后我就使用使用batchUpdate包裹setData,发现还是不能撤销和重做,然后我又加入了节点的其他属性设置,发现batchUpdate包裹的position函数可以,只是setData不行。希望x6团队改进一下。
归为一个吧,https://github.com/antvis/X6/issues/4693