JointJs - onConnect Link event

I am trying to create a board where the user can dynamically add blocks and associate blocks with links. (Something like this , but dynamic) I use the JointJs framework, and so far everything is working as expected, but I need to show some information when the user connects to two blocks. My problem is that I cannot find an event to handle when blocks are connected .

I looked through this question , but in my example I don't have an instance of a link to attach an event.

Here you can see my example.

And this is how the block is added to the board. magnet : truth in the text property is what makes the text pluggable. I really need help finding an event to handle when the link is connected.

var rect = new joint.shapes.basic.newRect({ position: { x: position, y: position }, size: { width: 100, height: 40 }, attrs: { rect: { 'stroke-width': '1', stroke: 'black', rx: 3, ry: 3, fill: 'blue'}, text: { text: 'Block', magnet: true, } } }); graph.addCell(rect); 

I also looked at the mouseUp event and coordinates, but nothing came of it .. I really appreciate some help

+8
javascript jointjs
source share
1 answer

The change:source and change:target events (like all other events triggered by cell models) are propagated to the chart, so you don’t need a link to your links, you can do something like:

 graph.on('change:source change:target', function(link) { if (link.get('source').id && link.get('target').id) { // both ends of the link are connected. } }) 
+12
source share

All Articles