Binding more than one value

Dear Northwoods Software,
we are evaluating GoJS for a small internal project, I’m a beginner and I would like to ask a small question.

I already understood how to bind simple model properties to nodes and link templates and also how to use conversion functions to translate a text into a color, like in this perfectly working case:

function nodeType2Color(type) { if (type === "BPOP") return "OrangeRed"; if (type === "BOMP") return "Peru"; return "white"; }

myDiagram.linkTemplate = $(go.Link, $(go.Shape, new go.Binding("stroke", "cabletype", cableType2Color)));

I’m asking if it’s possible to merge more than one property and pass it to a conversion function.
Suppose I have the following data for a node:


And this simple merging function:

function mergeTexts(text1, text2) { return text1.concat(text2); };

How can I write a function that binds “label” and “type” to a new text to be used as a label (“foobar”, in this case) for the node or the link? The following try is (obviously) not working…

myDiagram.linkTemplate = $(go.Link, $(go.Shape, new go.Binding("text", "label", "type", mergeTexts)));

I hope I have explained well, English is not my main language.

Thanks in advance,

Use the empty string as the source property name, and the whole data object will be passed as the first argument to the conversion function.

  new go.Binding("text", "", function(data) { return data.label.concat(data.type); })

As the following documentation suggests, for efficiency reasons you should not use empty string source property name unless needed for this purpose.

1 Like

Perfect, just what I was looking for… thank you very much, Walter!