wangduanduan / jsplumb-chinese-tutorial

jsplumb中文教程, README中没有的内容,可以查看项目的Wiki。有问题提issue
https://github.com/wangduanduan/jsplumb-chinese-tutorial/wiki
1.3k stars 249 forks source link

新增节点如何建立连接线,并保证布局正确及可拖拽 #15

Closed CodeLines3 closed 4 years ago

CodeLines3 commented 4 years ago

需求:在已经初始化和已建立连接关系的节点情况下,点击某节点上的添加按钮,在此节点的嵌套结构上添加子节点,并进行父子节点连接,保证连接线不偏移 背景:Vue,Ng6+等场景,增加节点通过更新data数据实现 现实现代码:

this.instance.setId(el, newId); //   已有实例上设置新添加节点的id
this.instance.connect({  //  已有实例上添加新的连接
        source: 'item_left',
        target: 'item_right',
        endpoint: 'Rectangle',
        connector: ['Bezier'],
        anchor: ['Left', 'Right']
      })
this.instance.revalidate(el) // 节约资源 重绘当前嵌套结构的父元素
this.instance.repaintEverything() //又试了这个 确保没有问题重绘所有

结果: 不进行setId() 设置ID connect方法提示 Cannot establish connection - source does not exist 执行setid 后可以正常建立连线但是source端连线锚点严重偏移; 并且之前设置的 jsPlumb.draggable('.window')在新添加的节点class=“window”上不起作用

1、文档是否存在在已有连接上添加新的连接的方法,类似jsPlumb.getConnections()对应的setConnections({source, target}) 2、或者其他重新可添加节点,并建立连接的可通知jsplumb内部重新更新的方法

shanpancheng commented 4 years ago
el

你那边解决了吗 我这边也是同样的问题 使用connect连接后再移动元素会出现端点偏移 。如果再从另外一个端点拖出连线的时候就会自动复原 再移动又偏移里 。 但是拖拽出来的连线就不会有这个问题

BlackTeaChan commented 4 years ago

使用jsPlumb.connect({ source:xxx, target:xxx })生成的连接线样式会跑偏

建议使用jsPlumb.connect({ uuids:[xxx,xxx] })生成,这种方式生成的线和拖动生成的线样式一致

wangduanduan commented 4 years ago

参考 @BlackTeaChan