Change the Property which is used for binding in GoJS Node Template

Normally, your TextBlock’s Binding should have been:

new go.Binding("text", "property1")

But if you want to change the result of the binding dynamically, you have several choices. Is the property whose value you want to show supposed to affect all nodes, or just one particular node?

If it’s just per node, not all nodes, then you could add a property to the data object to control which property to return in the conversion function:

  new go.Binding("text", "", function(data) { return data.show1 ? data.property1 : data.property2; })

Or maybe even:

  new go.Binding("text", "", function(data) { return data[data.show]; })

if you really want to be more general about it.

Alternatively, if you want to change the property shown in the TextBlock in all such nodes, then you could change the conversion function to depend on some global variable. You would then just need to call Diagram.updateAllTargetBindings.

Remember to make all changes grouped together within a single transaction.