Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 6977

makeTwoWay on arrays using the empty binding

$
0
0

@felix wrote:

Hello,

My data contains a list, which I would like to be user-editable, but I am failing to make the two-way binding work. E.g. the data for a node looks this:

{ "text":"hello", "list":[1,2,3] }

I am displaying such a node like this:

$(go.Node, "Auto", $(go.Shape, "Rectangle"),
  $(go.Panel, "Vertical",
    $(go.TextBlock, new go.Binding("text","text")),
    $(go.Panel, "Table", new go.Binding("itemArray","list"),
      { itemTemplate: $(go.TextBlock, new go.Binding("text","").makeTwoWay(), {editable:true}) }
    )
  )
)
-----------
|  hello  |
|    1    |
|    2    |
|    3    |
-----------

The user editing any item 1,2,3 in the list does not update the model. I see from http://gojs.net/latest/api/symbols/Binding.html that

Because in this example the source property name is the empty string, and because one cannot replace the whole source data object, any return value from the conversion function is ignored.

I see from e.g. https://forum.nwoods.com/t/binding-to-structured-node-data/5336 that there is sometimes a way to bind the data anyway, using a backConverter. I tried passing such a function, bC, to .makeTwoWay(bC):

function bC(target,dataobj) {
  dataobj = target
}

This (probably as expected ..) has no effect. It seems that target is just the new value and dataobj the old value.

How can you make the two-way binding work for elements of an array?

Thanks,

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6977

Latest Images

Trending Articles



Latest Images