简体   繁体   English

在jsPlumb中将数组用作目标

[英]Using array as target in jsPlumb

I am trying to create connections in jsPlumb from one source to multiple targets. 我试图在jsPlumb中创建从一个源到多个目标的连接。 I want to define the targets using an array. 我想使用数组定义目标。 However, whenever I try to do this jsPlumb always simply chooses the first item in the array, rather than using all of them. 但是,每当我尝试执行此操作时,jsPlumb始终只是选择数组中的第一项,而不是全部使用它们。

For example, I define my array like so using the id's of two elements: 例如,我使用两个元素的ID来定义数组:

var test = ['s4', 's3'];

Then, the jsPlumb to create the programmatic connection: 然后,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"} ] 

    });


})

This only ever creates a connection between #element1 and #s4. 这只会在#element1和#s4之间建立连接。 What am I getting wrong? 我怎么了? I can't find much documentation on how to use an array in the context of a programmatic connection. 我找不到太多有关如何在程序化连接的上下文中使用数组的文档。

Try to loop your code for multiple targets like below: 尝试为多个目标循环代码,如下所示:

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"
        })
}

Similar question: How can I connect multiple targets from a single source? 类似问题: 如何从一个来源连接多个目标?

As stated in the docs, you can't pass an array in the target field of .connect method. 如文档中所述,您不能在.connect方法的目标字段中传递数组。

DOCS - http://jsplumbtoolkit.com/apidocs/classes/jsPlumbInstance.html#method_connect DOCS- http://jsplumbtoolkit.com/apidocs/classes/jsPlumbInstance.html#method_connect

For connecting the same source to multiple targets, just use the .connect method multiple times with different target everytime. 要将同一源连接到多个目标,只需多次使用.connect方法,每次都使用不同的目标。

If you want to limit the number of connections which can be made from a single endpoint (unlimited by default), then you can use the maxConnections property - http://jsplumbtoolkit.com/apidocs/classes/jsPlumbInstance.html#method_makeTarget 如果要限制可以从单个端点进行的连接数(默认情况下为无限制),则可以使用maxConnections属性maxConnections : //jsplumbtoolkit.com/apidocs/classes/jsPlumbInstance.html#method_makeTarget

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM