简体   繁体   English

使用jsPlumb将端点添加到部门

[英]Add endpoints to a division using jsPlumb

I am working with the jsPlumb library where I have a toolbox from which I need to drag and drop elements onto the container and then provide an option for the users to connect the dropped elements within the container. 我正在使用jsPlumb库,这里有一个工具箱,我需要从该工具箱中将元素拖放到容器上,然后为用户提供一个选项,以便用户将所放置的元素连接到容器中。

I am currently able to drag and drop an element. 我目前能够拖放一个元素。 But what I need to do here is to drop the element with the connectors/endpoints(anchors). 但是我在这里要做的是删除带有连接器/端点(锚)的元素。

I have defined the connector properties as follows. 我定义了连接器属性,如下所示。

jsPlumb.ready(function() {

    jsPlumb.setContainer($('#container'));

  //Connector Defaults
    var connectorProperties = {
            isTarget:true,
            isSource:true,
            maxConnections:-1,
            anchors:["Left","Right"],
            endpoint:["Dot",{
                radius:4
            }],
            connector:["Flowchart"],
            connectorStyle:{
                strokeStyle:"5c96bc",
                linewidth:1,
                outlineColor:"transparent",
                outlineWidth:4
            },
            paintStyle:{
                fillStyle:"transparent"
            },
            hoverPaintStyle: {
                fillStyle:"FF0000"
            }
    };

And once the first element is dropped, I have defined the connector properties over that dropped element. 一旦删除了第一个元素,我就定义了该删除的元素的连接器属性。

drop: function (e, ui) {

    var mouseTop = e.clientY;
    var mouseLeft = e.clientX;

    var dropElem = ui.draggable.attr('class');
    droppedElement = ui.helper.clone();
    ui.helper.remove();
    $(droppedElement).removeAttr("class");
    $(droppedElement).draggable({containment: "container"});
    jsPlumb.repaint(ui.helper);


    //If the dropped Element is a TABLE then->
    if (dropElem == "stream ui-draggable ui-draggable-handle") {
        var newAgent = $('<div>');
        jsPlumb.addEndpoint(newAgent,connectorProperties);
        newAgent.attr('id', i).addClass('streamdrop');
        var elemType = "table";
        $("#container").addClass("disabledbutton");
        $("#toolbox").addClass("disabledbutton");

        $('#container').append(newAgent);

But am unable to view the connectors on the dropped element. 但是无法查看放置的元素上的连接器。 Only the streamdrop div is dropped on the container and the container and the toolbox are disabled according the declared code that follows the connector addition code above. 仅将streamdrop div拖放到容器上,并且根据上面连接器添加代码之后的声明代码禁用容器和工具箱。

在此处输入图片说明

Any suggestions on why I am unable to view the connectors/endpoints on the dropped element and how to resolve this error will be highly appreciated. 对于为什么我无法查看放置的元素上的连接器/端点以及如何解决此错误的任何建议,将受到高度赞赏。

I think u did lot of stuff which is not needed. 我认为您做了很多不需要的事情。 Suggestion Use - jsPlumb.addEndpoint($(droppedElement),connectorProperties); 建议使用-jsPlumb.addEndpoint($(droppedElement),connectorProperties); Can you create a fiddle for better understanding. 您能否制造一个小提琴以更好地理解。

var newAgent = $(''); var newAgent = $(''); jsPlumb.addEndpoint(newAgent,connectorProperties); jsPlumb.addEndpoint(newAgent,connectorProperties);

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

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