Way to find previous element within a panel


Is there any way in element property binding function to get the previous element related to itself within a same panel?

sample code:

$(go.Panel, 'Horizontal', {},
    $(go.TextBlock, 'First Label'),
    $(go.TextBlock, 'Second Label',
         new go.Binding('stroke', '', function(data, target){
             //Any APIs to get first textblock ( something like target.getPrevElement()) ?


There isn’t anything exactly like .nextSibling or .previousSibling.

But you could do something like:

  $(go.Node, ...,
    $(go.TextBlock, "First Label", { name: "FIRST" }, ...),
    $(go.TextBlock, "Second Label", ...,
       new go.Binding("stroke", "", function(tb) { ... }).ofObject("FIRST")

In fact, if you are just going to use some settable property of the “FIRST” TextBlock as the value of the second TextBlock.stroke, you don’t even need a converter function:

  $(go.Node, ...,
    $(go.TextBlock, "First Label", { name: "FIRST" }, ...,
       new go.Binding("stroke", "color")),  // based on data.color
    $(go.TextBlock, "Second Label", ...,
       new go.Binding("stroke", "stroke").ofObject("FIRST")  // on 1st TextBlock.stroke

Note that element names (i.e. GraphObject.name), allowing one to call Panel.findObject, are scoped at each Part or each item Panel.

Hi Walter:

Thanks for the quick response.

I was try to avoid set name property since there are many textblocks in a panel, and each textblock’s stroke is exactly related on its previous textblock, I was thought using findObject may cause some performance issue as the textblock list growth.

No, sorry, there aren’t any such “relative source” bindings at this time. It’s been on the list of maybe-someday features since v0.0, though.