JointJS提供了从dia.Link.prototype.disconnect和dia.Link.prototype.remove等图表中删除链接的方法
但是,它们依赖于首先访问链接对象。有没有办法通过ID查询LinkJS的JointJS图(joint.dia.Graph
)?
我可以手动维护从ID到链接对象的JS映射,但这听起来很乏味。
答案 0 :(得分:2)
graph.getCell(linkId)不能做你想要的吗?
例如
public class PrintTriangleMirror {
public static void main(String [] args) {
int height = 7;
for (int row = 1; row <= height; row++) {
for (int space = 1; space < row; space++) {
System.out.print(" ");
}
for (int column = 1; column <= height - row + 1; column++) {
System.out.print("[_]");
}
System.out.println();
}
}
}
答案 1 :(得分:0)
如果您想要访问任何链接,您有两个选项,然后可以删除它们
_.each(cellView.paper.model.getLinks(), function(link) {
console.log(link.id, link.get('source'), link.get('target'))
})
OR
_.each(cellView.paper.model.get('cells'), function(cell) {
if (cell instanceof joint.dia.Link) {
// cell is a link
console.log(cell.id, cell.get('source'), cell.get('target'))
} else {
// cell is an element
console.log(cell.id, cell.get('position'), cell.get('size'), cell.get('angle'))
}
})
Courtsey David Durman本人
https://groups.google.com/forum/#!topic/jointjs/cWJAK9gSC-Q
在图表上你可以发出一个事件
graph.on('change:source change:target', function(link) {
you can use link.remove()
}