我正在尝试在 jsPlumb 中创建从一个源到多个目标的连接。我想使用数组定义目标。但是,每当我尝试执行此操作时,jsPlumb 总是简单地选择数组中的第一项,而不是使用所有项。
例如,我使用两个元素的 id 来定义我的数组:
var test = ['s4', 's3'];
然后,jsPlumb 创建编程连接:
jsPlumb.ready(function() {
jsPlumb.connect({
source:"element1",
target: test,
anchors:["Left", "Left" ],
endpoint:"Blank", /* note that you can also make this "image" if you want something fancy */
endpointStyle:{ fillStyle: "red"},
paintStyle:{strokeStyle:"red", lineWidth:3},
connector:[ "Flowchart", { cornerRadius:"200", stub:"40"} ]
});
})
这只会在 #element1 和 #s4 之间创建连接。我错了什么?我找不到太多关于如何在编程连接上下文中使用数组的文档。
最佳答案
尝试为多个目标循环代码,如下所示:
var start = 'element1';
var end = ['s4','s3'];
for(var i=0;i<end.length;i++)
{
jsPlumb.connect({
source:start,
target:end[i],
connector:[ "Flowchart", { cornerRadius:"200", stub:"40"} ],
paintStyle:{strokeStyle:"red", lineWidth:3},
endpointStyle:{ fillStyle: "red"},
anchors:["Left", "Left" ],
endpoint:"Blank"
})
}
类似问题:How can I connect multiple targets from a single source?
关于javascript - 在 jsPlumb 中使用数组作为目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24312538/