Conditonal 2way binding

On links the user can change the logical direction (i.e flip the arrowhead) which changes the label. For example a link for Person → drives → car, would then change to Car → is driven by → person.

Furthermore the user can change the default label. The data model has 3 attribute:

I can have a binding like this to show the correct value:

new go.Binding("text", "", function(data) {
  return data.isFlipped ? data.flippedLinkText : data.linkText;

but how would I define the makeTwoWay conversion function to update the correct model data value?


If you look at the documentation for Binding.makeTwoWay Binding | GoJS API or for Binding.backConverter Binding | GoJS API, you will see that the converter will be given, in addition to the new value as the first argument, the data object and the model as the second and third arguments.

So if your link data were something like:

  { from: 1, to: 3, a: "A", b: "B", c: true },
  { from: 2, to: 4, a: "AA", b: "BB", c: false },

then your TextBlock could be something like:

$(go.TextBlock, { editable: true },
  new go.Binding("text", "", data => data.c ? data.a : data.b)
      .makeTwoWay((val, data, model) => model.set(data, data.c ? "a" : "b", val)))

Read the full preamble to the Binding page but missed the details. Thanks for the info.