Get object from changedListener

Hey guys, I am trying to get object from Changed event, the object on which the change occurs. According to docs there is a parameter on given event, which contains said object, but I have problem accesing data on this object. I`ll give an example, imagine a simple diagram with one node (Screenshot by Lightshot) on which I have enabled editable text field. I need to know, when this textfield is changed and on what Node. For moving the nodes I am using this kind of code:

diagram.addDiagramListener('SelectionMoved', (e) => { diagram.selection.each((item) => { if (item instanceof go.Node) { console.log(item.data) // <--- this is what I need ...

But with changed event there is no diagram.selection, so how can I get to the same item.data with Changed event?

I’m assuming that you have either declared a “ModelChanged” listener on your Diagram or a Changed listener directly on your Model.

The listener will get a lot of ChangedEvents, ChangedEvent | GoJS API. The ChangedEvent.object will be the model data object that was modified. The other ChangedEvent properties describe the modification.

If you are trying to track data changes to send to your server, I suggest that you look for e.isTransactionFinished and then scan the Transaction.changes list for all of the ChangedEvents that you care about. The ChangedEvent documentation describes this. Search for references to “isTransactionFinished” throughout the documentation and samples.

Yes, I have changed listener on diagram:

diagram.addChangedListener((e) => { if (e.propertyName === 'text') { console.log(e.object); //here I want to have the same thing as I have in diagram.selection, the Node on which is attribute data }

But I am struggling to get from the event to the specific node on which the change occured. In transaction changes there are changed events, which is fine, but aside from changes I also need to know on which Node in Diagram they occured (on each Node I have data in which I have additional info for communication with my server, i.e. UUID of object on server-side)

No, that gets ChangedEvents from the Diagram, not from the Model.

Change your code to be:

diagram.addModelChangedListener(. . .

Thanks Walter, that was a lifesaver :)