Jsplumb add connection programmatically using endpoints

邮差的信 提交于 2019-12-05 15:20:46

To connect using already existing endpoints you can make use of the Uuid's of the endpoints:

jsPlumb.ready(function () {  
    var e0 = jsPlumb.addEndpoint("container0",{uuid:"ep1"}),  //set your own uuid for endpoint for later access.
    e1 = jsPlumb.addEndpoint("container1",{uuid:"ep2"});  
    jsPlumb.connect({ uuids:[e1.getUuid(),e2.getUudi()] }); // (or) jsPlumb.connect({ uuids:["ep1","ep2"] });
});

According to the API jsPlumb.connect() can receive

array of UUIDs of the two Endpoints

but it's not the only way to connect endpoints as there's also another way (which is more common as it's used to connect two objects) with source and target parameters who can receive String or Object (as a DOM object) or directly an Endpoint (which is not the same as a DOM selector of an endpoint, for instance it can be let firstEndpoint = jsPlumb.addEndpoint()).

So if, like me, you don't want to use universally unique identifier you can stick to classical source target and give endpoint as parameters.

jsPlumb.connect({ source: firstEndpoint, target: jsPlumb.selectEndpoints() }); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!