如何在draw2d.js中删除连接

How to delete connection in draw2d.js?

本文关键字:删除 连接 js draw2d      更新时间:2023-09-26

我想删除draw2d.js中两个对象之间的连接。我正在试图找到删除连接的直接方法,但我没有找到。所以请告诉我是否有任何方法可以删除或断开连接。提前感谢!

不支持CommandStack

canvas.remove(connection);

支持CommandStack(撤消/重做):

var cmd =  new draw2d.command.CommandDelete(connection);
canvas.getCommandStack().execute(cmd);
 draw2d.ContextmenuConnection.prototype.getContextMenu = function() {    
     var menu = new draw2d.Menu();
     menu.appendMenuItem(new draw2d.MenuItem("Disconnect", null, function() {
         //draw2d.Connection.workflow.removeFigure(draw2d.Connection.prototype);
         var cmd =  new draw2d.CommandDelete(**draw2d.Connection**);
         draw2d.Connection.prototype.workflow.getCommandStack().excute(cmd);
     }));
 };

您必须将一个对象移交给CommandDelete和NOT的构造函数。draw2d。连接

见下文:

 draw2d.ContextmenuConnection.prototype.getContextMenu = function() {    
     var menu = new draw2d.Menu();
     var oThis = this;
     menu.appendMenuItem(new draw2d.MenuItem("Disconnect", null, function() {
         //draw2d.Connection.workflow.removeFigure(draw2d.Connection.prototype);
         var cmd =  new draw2d.CommandDelete(oThis);
         draw2d.Connection.prototype.workflow.getCommandStack().excute(cmd);
     }));
 };