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”).
But the panel of that item is still there (still 5 items there, althought “ERP-System” was deleted):
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.
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
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.