2017-09-18 58 views
0

我正在使用jsPlumb库,我有一个工具箱,我需要从中将元素拖放到容器上,然后为用户提供一个选项,以便将容器内的已放置元素。使用jsPlumb将端点添加到部门

我目前能够拖放一个元素。但是我需要在这里做的是用连接器/端点(锚点)放置元素。

我已经定义了如下的连接器属性。

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

一旦第一个元素被删除,我已经定义了该删除元素上的连接器属性。

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); 

但是我无法查看掉落元素上的连接器。只有streamdrop div放在容器上,并且根据上面的连接器添加代码的声明代码禁用容器和工具箱。

enter image description here

为什么我无法查看连接任何建议/丢弃的元素,以及如何解决这个错误在端点上,将不胜感激。

回答

0

我觉得你做了很多不需要的东西。建议使用 - jsPlumb.addEndpoint($(droppedElement),connectorProperties); 你可以创建一个小提琴更好的理解。

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

+0

感谢您的回复。 –