javascript - jsPlumb: delete a draggable element - Stack Overflow

I have a “canvas” where I allow the user to add draggable boxes and connect them with jsPlumb. I want t

I have a “canvas” where I allow the user to add draggable boxes and connect them with jsPlumb. I want to let them delete one of those boxes at some point in time. To handle that, I first detach all connections and remove endpoints from the target element, which works fine

jsPlumb.detachAllConnections(targetBoxId);
jsPlumb.removeAllEndpoints(targetBoxId);

I then remove the actual DOM element:

$(targetEl).remove();

At this point, jsPlumb starts freaking out and doesn’t allow me to drag the remaning elements anymore:

I can keep resizing the boxes and making new connections, but dragging an element keeps failing and emitting the above error.

Is there something I’m doing wrong? In other words, is there a proper-er way to remove a jsPlumb element in a “draggable” environment?

I have a “canvas” where I allow the user to add draggable boxes and connect them with jsPlumb. I want to let them delete one of those boxes at some point in time. To handle that, I first detach all connections and remove endpoints from the target element, which works fine

jsPlumb.detachAllConnections(targetBoxId);
jsPlumb.removeAllEndpoints(targetBoxId);

I then remove the actual DOM element:

$(targetEl).remove();

At this point, jsPlumb starts freaking out and doesn’t allow me to drag the remaning elements anymore:

I can keep resizing the boxes and making new connections, but dragging an element keeps failing and emitting the above error.

Is there something I’m doing wrong? In other words, is there a proper-er way to remove a jsPlumb element in a “draggable” environment?

Share Improve this question edited Feb 28, 2013 at 23:02 Arnold asked Feb 28, 2013 at 22:57 ArnoldArnold 2,4201 gold badge27 silver badges46 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 1

You did remove the connections and the endpoints. But before you remove() the object from DOM you have to jsPlumb.detach() it:

jsPlumb.detachAllConnections(targetBoxId);
jsPlumb.removeAllEndpoints(targetBoxId);
jsPlumb.detach(targetBoxId); // <--
targetBoxId.remove()

I was also having the same problem when trying to delete, inside a specific div, all the draggable elements and their connections...

I found out that it has to do with the way the connections are deleted. I was only using detachAllConnections, which apparently still leaves the endpoints in the elements I wanted to delete (that caused trouble after deleting them).

I had to use instead jsPlumb.deleteEveryEndpoint() which will not only delete the connections but also the endpoints, giving no error after also deleting the elements :)

This snippet is working for me:

var targetBoxId = '#' + window.idOfCaller;

jsPlumb.detachAllConnections(window.idOfCaller);
jsPlumb.removeAllEndpoints(window.idOfCaller);
$(targetBoxId).remove(); 

Notice the difference between the detachAllConnections and removeAllEndpoints where passing only the string id e.g x1 and the remove were passing the #x1

Hi I am using this currently and I guess this will help you for sure.

jsPlumb.ready(function(){
    ShowStartNode() ;
});
function ShowStartNode(){
    var newState = $('<div>').attr('id', 'start').addClass('item');
    var title = $('<div>').addClass('title').text('Start');
    var connect = $('<div>').addClass('connect');
    newState.css({
      'top': '80px',
      'left': '500px'
    });
    jsPlumb.makeTarget(newState, {
      anchor: 'Continuous',
      connector:[ "Flowchart" ]
    });
    jsPlumb.makeSource(connect, {
      parent: newState,
      anchor: 'Continuous',
      connector:[ "Flowchart" ]
    });
    newState.append(title);
    newState.append(connect);
    $('#centerdiv').append(newState);
    jsPlumb.draggable(newState, {
      containment: '#centerdiv'
    });
    newState.dblclick(function(e) {
      jsPlumb.detachAllConnections($(this));
      $(this).remove();
      e.stopPropagation();
    });         
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745483705a4629672.html

相关推荐

  • javascript - jsPlumb: delete a draggable element - Stack Overflow

    I have a “canvas” where I allow the user to add draggable boxes and connect them with jsPlumb. I want t

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信