node.updateRelationshipsFromData does not work

Hi,

following data is bound to a node:
image

I pass the node.data object to another component, which deletes one item from the types array. Now the item in types array with index 3 is deleted (“erp”).
image

I execute

...
node.updateRelationshipsFromData();
diagram.commitTransaction("delete type");

But the panel of that item is still there (still 5 items there, althought “ERP-System” was deleted):
image

The following works (at least for the panel), but shouldnt updateRelationshipsFromData do the same job?
node.data = JSON.parse(JSON.stringify(typeGroup));

No, because Part.updateRelationshipsFromData only updates relationships with other Parts.

But even if you had called Part.updateTargetBindings, I’m not sure that would help, because the value of node.data.types has not changed – it’s still the same Array.

You can force it by calling Panel.rebuildItemElements on the Panel that has its Panel.itemArray property referring to a modified Array.

Maybe we should make this more convenient in version 2.

understand.

Is it ok to set the node.data again or will this cause any side effects?

Although I believe it might be possible, it would be difficult to set Node.data because of all of the existing references to the old data. And it would be especially difficult if the key changed.

Note that the documentation states that you should not modify Panel.data if the Panel was created automatically as part of the template/model/data-binding system. Panel | GoJS API

thank you, although I don´t have links to that specific node I will use:

removeArrayItem(_myArray_, index);

I have a related question:

When this node is modified, I need to remove other nodes. Those nodes have links connected to and from them. When I remove those nodes by calling

diagram.remove(node);

everything is ok.
But when I use

diagram.model.removeNodeData(node.data);

then the node is removed, but the links remain.

Do I need additional steps when I remove a node using the model functions?

Yes, if you use Model.removeNodeData, the links will remain. See Model | GoJS API. Before removing, you could get the list of connected links and call Model.removeLinkData, but it may be easier to just call Diagram.remove if you want to remove everything together.

Here’s an item in the future version 2.0 change log:

Improved Model.updateTargetBindings and Part.updateTargetBindings to update Panels that have Panel.itemArray data bound if the contents of the Array have changed. In version 1, the reference to the Array had to have changed – the Panel.itemArray had to have been replaced. In version 2, the Panel.itemArray property setter checks to see if all of the Array items have corresponding Panels and that all child Panels correspond to Array items (i.e. Panel.data refers to the Array item), even if the new property value is a reference to the same Array that it had been before.