[英]Remove a connection between two nodes
I'm trying to remove an existing connection(DragConnectionCreatePolicy) between two nodes. 我正在尝试删除两个节点之间的现有连接(DragConnectionCreatePolicy)。 I tried two ways, the first using this command: 我尝试了两种方法,第一种使用此命令:
this.canvas.remove(connection)
but it returns this: EXCEPTION: figure.getCanvas is not a function
this.canvas.remove(connection)
但返回以下内容: EXCEPTION: figure.getCanvas is not a function
The second one 第二个
var cmd = new draw2d.CommandDelete(connection);
this.canvas.getCommandStack().execute(cmd)
instead returns EXCEPTION: draw2d.CommandDelete is not a constructor
而是返回EXCEPTION: draw2d.CommandDelete is not a constructor
What am I mistaking? 我在误会什么?
I'm using draw2d inside an Angular 2 component. 我在Angular 2组件中使用了draw2d。
export class sampleDraw implements OnInit {
canvas:any;
createGraph() {
this.canvas = new draw2d.Canvas("canvas-div");
}
ngOnInit(){
this.createGraph()
}
}
There is code which you want in draw2d libray. 在draw2d libray中有您想要的代码。 I think you can remove the connection that already connected like this: 我认为您可以像这样删除已经连接的连接:
this.canvas.lines.remove(connection);
connection.setCanvas(null);
connection.disconnect();
UPDATE: 更新:
I found a way to remove any items in draw2d. 我找到了一种方法来删除draw2d中的所有项目。 Please define the command to delete the item. 请定义删除项目的命令。 And execute it. 并执行它。
let cmd = connection.createCommand(new draw2d.command.CommandType(draw2d.command.CommandType.DELETE)); if (cmd !== null) { connection.getCanvas().getCommandStack().execute(cmd); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.