Quantcast
Channel: Northwoods Software - Latest topics
Viewing all articles
Browse latest Browse all 7421

Obtaining information from a links connected node after it's deleted

$
0
0

@GSA wrote:

I currently need to obtain information about a node when it's deleted, as well as from the nodes connected to a link when the link is deleted. I have the following code:

myDiagram.addModelChangedListener(function(evt) {
    // ignore unimportant Transaction events
    if (!evt.isTransactionFinished) return;
    var txn = evt.object;  // a Transaction
    if (txn === null) return;
    // iterate over all of the actual ChangedEvents of the Transaction
    txn.changes.each(function(e) {
        // ignore any kind of change other than adding/removing a node
        if (e.modelChange === "nodeDataArray") {
            // record node insertions and removals
            if (e.change === go.ChangedEvent.Insert) {
                console.log(evt.propertyName + " added node with id: " + e.newValue.id);
            } else if (e.change === go.ChangedEvent.Remove) {
                console.log(evt.propertyName + " removed node with id: " + e.oldValue.id);
            }
        }
        if (e.modelChange === "linkDataArray")
        {
            if (e.change === go.ChangedEvent.Insert) {
                console.log(evt.propertyName + " added link between nodes : " + myDiagram.findNodeForKey(e.newValue.from).data.id + " and " + myDiagram.findNodeForKey(e.newValue.to).data.id);
            } else if (e.change === go.ChangedEvent.Remove) {
                console.log(evt.propertyName + " removed link between nodes: " + myDiagram.findNodeForKey(e.oldValue.from).data.id + " and " + myDiagram.findNodeForKey(e.oldValue.to).data.id);
            }
        }
    });
});

This works fine. However, there is one problem. When I delete a node and the connected links are automatically cleaned up, it's not able to find the node that was just deleted. I assume this is because links are being cleaned up AFTER the node is gone. Is there a way to get around this? One possible solution I am thinking about is forcing connected links to clean up first when you start a deletion, but I'm unsure about how to go about doing this.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 7421

Trending Articles