Reputation: 18667
JointJS offers methods for removing links from graphs such as dia.Link.prototype.disconnect and dia.Link.prototype.remove
However, they depend on having access to the link object in the first place. Is there any way to query a JointJS graph (joint.dia.Graph
) for the link object by ID?
I could manually maintain a JS mapping from ID to link object, but that just sounds tedious.
Upvotes: 0
Views: 2146
Reputation: 773
If you want access to any link, you have two options then you can remove them
_.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 himself https://groups.google.com/forum/#!topic/jointjs/cWJAK9gSC-Q
else on graph you can emit an event
graph.on('change:source change:target', function(link) {
you can use link.remove()
}
Upvotes: 0
Reputation: 7051
Does graph.getCell(linkId) not do what you want?
For example
graph.removeCells(graph.getCell(linkId))
Upvotes: 2