Hi,
I have several nodes that share a reference to an element in an array (see below). How can I update sharedObj so Node1 and Node2 reflect the changes?
sharedObj={foo: bar}
Node1={name: “One data”, data:[sharedObj,other1,other2]}
Node2={name: “Two data”, data:[sharedObj,other3,other4]}
Maybe you want to use Model.modelData alongside a Binding.ofModel binding. See GoJS Data Binding -- Northwoods Software.
Thanks for your quick answer.
In my case my Node1 and Node 2 have a panel that looks something like shown below. The main data object has a properties property that is an array of objects of the same type. One of those objects within properties is our SharedObj . The latter is also a member of the properties belonging to Node2
In this case it would suffice to say new go.Binding("itemArray", properties)..ofModel()
?
It somehow sounds like I would be binding the array as if it were the shared object, which is not my case…
Snippet 1 – Template
gMake(go.Panel, "Auto", {
stretch: go.GraphObject.Fill, minSize: new go.Size(100, 20)
}, gMake(go.Shape, "Rectangle", {
fill: "white",
}),
gMake(go.Panel, "Vertical", {
margin: 4,
name: properties,
defaultAlignment: go.Spot.Left,
},
gMake(go.Panel, "Vertical", {
name: "items",
defaultAlignment: go.Spot.Left,
itemTemplate: propertyShape,
}, new go.Binding("itemArray", properties)
),
this.ellipsis
))
Not quite. I think you want a separate binding that looks at the modelData. You can then pull data from the shared object in that binding.
In this codepen, I have a TextBlock bound to modelData.sharedObj, and I take the text property from there to update the text.