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

attr({})方法当去掉一个样式时无效 #3758

Closed
bighhhh opened this issue Jul 10, 2023 · 10 comments
Closed

attr({})方法当去掉一个样式时无效 #3758

bighhhh opened this issue Jul 10, 2023 · 10 comments
Labels
type: discussion 讨论 Usage questions, guidance, and other discussions

Comments

@bighhhh
Copy link

bighhhh commented Jul 10, 2023

问题描述

我改变前的attr是{water:{fill:"#37cfe7","visibility: "hidden"}}后来调用attr({water:{fill:"#37cfe7"}})设置,但是visibility这个属性在对象中去掉了,但是画面并没有更新为显示状态

重现链接

重现步骤

开始attr为
{
water:{
fill:"#37cfe7",
"visibility: "hidden"
}
}
调用attr设置后节点应该转为显示状态
cell.attr({
water:{
fill:"#37cfe7"
}
})

预期行为

visibility样式去掉后更新后页面中节点应该转为显示状态

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox ...]
  • X6 版本: [2.11.1 ...]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response

@bighhhh
Copy link
Author

bighhhh commented Jul 10, 2023

设置了overwrite:true也没有效果

@NewByVector
Copy link
Contributor

可以通过设置 {water:{fill:"#37cfe7","visibility: "visible"}} 让元素显示,如果只是去掉这个属性的话,元素内容没有更新。

@NewByVector NewByVector added the type: discussion 讨论 Usage questions, guidance, and other discussions label Jul 10, 2023
@bighhhh
Copy link
Author

bighhhh commented Jul 11, 2023

可以通过设置 {water:{fill:"#37cfe7","visibility: "visible"}} 让元素显示,如果只是去掉这个属性的话,元素内容没有更新。

好吧,因为我这边visibility这个属性是用户在我编辑器界面动态添加的样式,当数据为用户设置的某个值时就会添加上这个样式,不是某值时就还原为初始状态,所以只是两个对象互换,如果是这样那我就只能对比这两个对象的差异然后手动移除多出来的样式了,这个以后会考虑修改吗?

@bighhhh
Copy link
Author

bighhhh commented Jul 11, 2023

奇怪了,我想直接用removeAttrs移除所有样式,然后在setAttrs添加所有样式居然页面也没有变化。
而且只用removeAttrs移除所有样式节点也没有变化,但是我调用attrs()方法获取到节点的样式确实都清空了

@bighhhh
Copy link
Author

bighhhh commented Jul 11, 2023

调用removeAttrByPath直接删除指定样式倒是起作用的

@NewByVector
Copy link
Contributor

@hhzhldhjl 这个属性如果是用户自己来设置的话,我理解使用 switch 或者 checkbox 更用户友好,提供两个选项:visible 和 hidden。

@bighhhh
Copy link
Author

bighhhh commented Jul 11, 2023

我这个地方是根据data的变化在原始态和用户修改样式后的状态来回切换,只是removeAttrs这个方法应该移除所有样式后页面会重新根据没有attr的形式来重绘才对吧?我这个没有重绘,是我写的问题还是我理解错这个方法了呢

@NewByVector
Copy link
Contributor

如果不是特殊需求不要使用 removeAttrs,因为它同时会清除所有内置的 attrs,你无法在外面通过 setAttrs 恢复的。
你如果是想覆盖之前的 visibility 属性,正确的做法是 node.attr('water/visibility', '')

@bighhhh
Copy link
Author

bighhhh commented Jul 12, 2023

如果不是特殊需求不要使用 removeAttrs,因为它同时会清除所有内置的 attrs,你无法在外面通过 setAttrs 恢复的。 你如果是想覆盖之前的 visibility 属性,正确的做法是 node.attr('water/visibility', '')

好吧,那只能这样了

@x6-bot
Copy link
Contributor

x6-bot bot commented Jul 12, 2024

This thread has been automatically locked because it has not had recent activity.

Please open a new issue for related bugs and link to relevant comments in this thread.

@x6-bot x6-bot bot locked as resolved and limited conversation to collaborators Jul 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: discussion 讨论 Usage questions, guidance, and other discussions
Projects
None yet
Development

No branches or pull requests

2 participants