如何删除draw2d.js中的连接?

时间:2012-07-16 12:23:58

标签: javascript draw2d-js

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

2 个答案:

答案 0 :(得分:0)

没有CommandStack支持:

canvas.removeFigure(connection);

CommandStack支持(撤消/重做):

var cmd =  new draw2d.CommandDelete(connection);
canvas.getCommandStack().excute(cmd);

答案 1 :(得分:0)

 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的构造函数而不是 draw2d.Connection

见下文:

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

 };