Archiv der Kategorie: GoJS

GoJS: Conditional Binding / Bind to another attribute when binding not exists


When an attribute is not appearing in the diagram model (nodeArray), a different property should be selected

Ansatz – Approach

The third paramater of the Binding Constructor can be used to declare a function that handles the nodeData.

Lösung – Solution

// the node template describes how each Node should be constructed
      diagram.nodeTemplate =
        $(go.Node, "Auto",  // the Shape automatically fits around the TextBlock
          new go.Binding("location", "loc", go.Point.parse),
          $(go.Shape, "RoundedRectangle",  // use this kind of figure for the Shape
            // bind Shape.fill to
            new go.Binding("fill", "color")),
            { margin: 5, width: 100 },  // some room around the text
            // bind TextBlock.text to

            new go.Binding("text", "", 
                return (data.text) ? data.text : data.key;