How to render label in a TextBlock


{“key”: 1, “text”: “John Wayne”, “call”: “Mr”}

I want a TextBlock that displays the text like:

Mr. John Wayne
With the values from the model data.

I tried:

$(go.TextBlock, {editable: true}, new go.Binding("text", "text", function(v) { return "Mr. "+v; }).makeTwoWay() )
The problems are:
  1. I can't reach the value of CALL from function(v)
  2. I don't want to change the values on the Model Data, only the "label displayed"

Can you help me?


Bind to the whole data object, rather than to a particular property on the data object:

new go.Binding("text", "", function(d) { return + " " + d.text; })

This is also demonstrated in many of the samples, such as the Basic sample.

The down-side to binding on the Object rather than on a particular property of the data is that every time any Bindings are evaluated, all such Bindings to “” are evaluated, since GoJS cannot know which properties had changed. So there’s a performance penalty to using such bindings.

Also, as should be clear, since you have a TwoWay Binding, your back-converter will have to be more complex. The documentation for Binding has an example:

Thanks again for the quick reply, Walter.

Works beautifully.