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

新建node/edge的时候 如何使用自定义id? #3002

Closed
cuidong626 opened this issue Dec 5, 2022 · 5 comments
Closed

新建node/edge的时候 如何使用自定义id? #3002

cuidong626 opened this issue Dec 5, 2022 · 5 comments

Comments

@cuidong626
Copy link
Contributor

功能描述

cell 构造函数会判断id是开发配置还是采用uuid,但是clone的时候就没办法开发自定义了。
希望提供一个机制,可以自己根据业务规则创建id

image
image

期望解决方案

新建node/edge的时候 如何使用自定义id?
希望提供一个机制,可以自己根据业务规则创建id

@cuidong626
Copy link
Contributor Author

同需求问题 #2789

@g0ngjie
Copy link

g0ngjie commented Dec 5, 2022

自己替换确实很麻烦,如果官方能提供自定义id生成方式会好很多。
目前我是在通过 createNode 时,在 metadata 中手动设定一个id。如果是拖拽情况下,需要参考这篇文档 https://x6.antv.vision/zh/docs/tutorial/basic/dnd#%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98。因为放置节点时,会重新生成 uuid

@NewByVector
Copy link
Contributor

创建节点的时候是可以通过配置 id 属性自定义 id 的,如果是 dnd 拖拽场景,请参考 常见问题

@leechor
Copy link

leechor commented May 26, 2023

  const validateNodeNew = function (
      droppingNode: Cell,
      options: any
  ): boolean | Promise<boolean> {
    const ctor = droppingNode.constructor as typeof Cell
    const props = droppingNode.getProp();
    const node =  new ctor({ ...props, "id": "abcd"})
    options.targetGraph.model.addCell(node)
    return false
  }

new Stencil({validateNode: validateNodeNew,})

@x6-bot
Copy link
Contributor

x6-bot bot commented May 26, 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 May 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants