-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Antv x6双击修改标签错误 #1919
Comments
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. |
因为默认的 setText 方法执行逻辑是: setText({ cell, value }) {
cell.attr('text/text', value)
}, 所以你这里需要修改成: const source = graph.addNode({
x: 180,
y: 60,
width: 100,
height: 40,
attrs: {
body: {
stroke: '#5F95FF',
fill: '#EFF4FF',
strokeWidth: 1,
},
label: {
text: 'test'
}
},
})
graph.on('cell:dblclick', ({ cell, e }) => {
const isNode = cell.isNode()
const name = cell.isNode() ? 'node-editor' : 'edge-editor'
cell.removeTool(name)
cell.addTools({
name,
args: {
event: e,
attrs: {
backgroundColor: isNode ? '#EFF4FF' : '#FFF',
},
setText({ cell, value }) {
cell.attr('label/text', value)
},
},
})
}) |
您好,很感谢您的解答,但是这解决不了双击后获取不到标签内容的问题。 |
给个可复现的 demo 吧 |
这个问题,node-editor默认的getText、setText比较诡异,你这么写就能正确获取、修改文字了,千万不要自定义,我试了...
|
@JamesTing getText 和 setText 方法就是为了解决你自定义 label 的场景。 |
我能理解你们的意思了。如果使用cell.attr('label/text', value),第一次正常 将“string1”改为“string2”,但是观察cell里面label还是“string1”,只是表面改成功了;第二次双击时 文本框里的原文本会变为“string1”。 |
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. |
Describe the bug
尝试使用双击修改标签,如果是按照官方API使用attrs.label.text来标识标签的话,双击后获取不到标签内容,修改框为空,代码如下:
const source = graph.addNode({
x: 180,
y: 60,
width: 100,
height: 40,
attrs: {
body: {
stroke: '#5F95FF',
fill: '#EFF4FF',
strokeWidth: 1,
},
label: {
text: 'test'
}
},
})
graph.on('cell:dblclick', ({ cell, e }) => {
const isNode = cell.isNode()
const name = cell.isNode() ? 'node-editor' : 'edge-editor'
cell.removeTool(name)
cell.addTools({
name,
args: {
event: e,
attrs: {
backgroundColor: isNode ? '#EFF4FF' : '#FFF',
},
},
})
})
将node的label改写为text双击就可以获取到标签内容,如下所示:
const source = graph.addNode({
x: 180,
y: 60,
width: 100,
height: 40,
attrs: {
body: {
stroke: '#5F95FF',
fill: '#EFF4FF',
strokeWidth: 1,
},
text: {
text: 'test'
}
},
})
但是attrs.text不是官方API内容,请问这个地方能明确下吗?
Your Example Website or App
chrome
Steps to Reproduce the Bug or Issue
https://x6.antv.vision/zh/examples/node/tool#editable
Expected behavior
attrs.label.text work well
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: