Identify or Remove Nodes connected to a selectedItem

Is there a way to find the name or identifier of nodes connected to a selectedItem?

I have a node with a button on it. When I click that button, it deletes the node and it's connections:

function removeNode() {
        var diagram = $("#Diagram").ejDiagram("instance");
        var selectedItem = diagram.model.selectedItems.children[0];
        if (selectedItem) {
            diagram.remove(selectedItem);
        }
    }

What I would like to do is also remove any node that is connected to that selected node.  Is this possible?

1 Reply 1 reply marked as answer

AR Aravind Ravi Syncfusion Team August 6, 2020 06:49 AM UTC

Hi Dsoftware, 
 
By using the node outEdges property, we can find the connector that is connected as out connector to the node through diagram findNode method. In the findNode method pass the node or connector name. So that if the any objects in the diagram with that name is present means, then it returns that object. Through the connector we can get the node which is connected to the connector using the connector’s sourceNode property. After get the sourceNode, remove the selected item and remove the node. Please refer to the below code snippet 
 
document.getElementById('remove').onclick = function () { 
        var diagram = $("#DiagramContent").ejDiagram("instance"); 
        var connector = diagram.findNode(diagram.model.selectedItems.children[0].outEdges[0]); 
        var nodeId = connector.targetNode; 
        diagram.remove(); 
        var node = diagram.findNode(nodeId); 
        diagram.remove(node); 
    } 
 
 
Regards 
Aravind Ravi 


Marked as answer
Loader.
Up arrow icon