gpt4 book ai didi

javascript - Jsplumb 分离连接

转载 作者:行者123 更新时间:2023-12-05 04:40:31 29 4
gpt4 key购买 nike

我正在尝试在单击小部件时断开连接。

引用帖子:

我在 newest CDNJS release 2.15.6 上,这是我尝试过的:

this.plumb.bind('click', function(conn){
connect.connections.splice(connect.connections.indexOf(conn.cn), 1);
this.plumb.deleteConnection(conn);
connect.render();
});
// jsPlumb: fire failed for event click : TypeError: undefined is not an object (evaluating 'this.plumb.deleteConnection')
this.plumb.bind('click', function(conn){
connect.connections.splice(connect.connections.indexOf(conn.cn), 1);
jsPlumb.deleteConnection(conn);
connect.render();
});

但是,这成功删除了连接,因为如果目标和源对应于已删除的连接,我将无法再添加新连接。我收到一条错误消息:

TypeError: null is not an object (evaluating 'x.endpoints[0]')    jsplumb.min.js

指的是 this issue ,

我试图切换到版本 5,但我没有在 https://github.com/jsplumb/jsplumb 上找到任何浏览器脚本,顺便说一句,在提供的演示中有一堆错误。


如果有以下任何一项,我将不胜感激:

  • 分离连接的方法
  • 就我的行为中的任何潜在错误提出建议
  • 最新稳定版CDN

minimum snippet to generate the error

setTimeout(()=>{
let source = document.createElement('div');
let target = document.createElement('div');
document.body.appendChild(source);
document.body.appendChild(target);
let instance = jsPlumb.getInstance({
PaintStyle: { strokeWidth: 1 },
Container: document.body,
});
function getConnection(){
return instance.connect({
source: source,
target: target,
cssClass: 'redLine',
endpoint: "Blank",
anchor:"AutoDefault",
overlays: [
["Arrow", {
location: 1,
width: 10,
length: 10
}
],
[ "Label", {
location:0.5,
label:"Label Text"
}
],
],
paintstyle: {
lineWidth: 1,
strokeStyle: 'black',
}
,
connector: ["Flowchart"],
});
}
let conn = getConnection();
jsPlumb.deleteConnection(conn, {
fireEvent: false, //fire a connection detached event?
forceDetach: false //override any beforeDetach listeners
});
conn = getConnection();
}, 0)

now we are trying to solve the issue on Github

最佳答案

这里的问题是在 jsPlumb 的默认实例上调用了 deleteConnection 方法,但其余代码使用的是特定实例:

let instance = jsPlumb.getInstance({
PaintStyle: { strokeWidth: 1 },
Container: document.body,
});

...

jsPlumb.deleteConnection(...) <-- should have been instance.deleteConnection

关于javascript - Jsplumb 分离连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70262071/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com