Question: Given a model that uses a parent-child relationship in which the child objects are used to power an itemArray, is it possible to get a reference to the parent object of the model from the child in a binding function.
Scenario: Where there are many child objects and binding is being used on some property, say the fill, it might be easier and less resource intensive to set the desired fill on the parent in the model rather than each child. Therefore, in the binding function we need to be able to get to the parent to read the fill.
Example: Based on the id of a child being odd or even set its fill to the appropriate color known to its parent (cut down for readability)
nodeDataArray= {parent: {fillOdd: 'red', fillEven: 'blue', children: [ {id: 1}, {id: 2}, {id: 3} ....]}
How to use this model where the children nodes act as an itemArray and have a binding function on the itemArray template similar to:
new go.Binding("fill", "", function(data) { return (data.id % 2) === 0 ? data.parent.fillEven : data.parent.fillOdd})
Additional Node: As far as my research goes I cannot see that JavaScript provides an automatic reference to the parent of a child object from the child perspective. One can add something in code but if we have to do that we may as well add the odd/even color details to the child in the first place and then not have to worry about potential memory leaks in dodgy JS interpreters.