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

Hi,

I have this condition where, I need to change the binding when I change a dropdown outside my map.

Could you please tell me how do I achieve this?

My Situation is something like this :

$$(go.TextBlock,
       new go.Binding("text", "" , function(data){
           return data.property1;})
    )

And in my dropdown change event,
I need to change the binding to data.property2 instead of data.property1.
I have tried set Model.setDataProperty but it didnt help.

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.