Go.Binding and nested properties

Hi

Does go.Binding support binding to nested properties such as new go.Binding("text", "queryResult.value")?

Currently, in order to produce the desired behaviour, I have to write code similar to this:

make(go.TextBlock, new go.Binding("text", "queryResult", function (v) { return v != null ? v.value : ""; }), { column: 1, font: goCommonTemplates.fonts.smallFont })

Is this the recommend way for doing it?

Thanks
Justin

No, it does not support property paths. So your implementation is correct.

Your code carefully checking for null points out one of the reasons why property paths can be more complex than they might seem.

Here’s a GOJS example that uses a Javascript Proxy to provide property paths…“deep.dot.path” properties to allow drilling into an object to dynamically get/set properties. I basically wrapped the code in https://www.npmjs.com/package/deep-dot into a Javascript Proxy, and provided more catcher methods to handle the required cases in GoJs (eg. iterating keys, key property descriptors, etc.). This would allow you to create go-bindings using the “deep.dot.path” as absolute binding keys on the fly. NOTE: I don’t support arrays in this example.

https://jsfiddle.net/L08qddog/3/

Yes, that’s a clever way to support property paths in data binding. But it requires the use of specially defined properties on the data objects, much as Backbone, Ember, and Knockout do. I suspect that get and set performance is poor too, although I have not tested that.

There is also a problem with it (version 3/5) at the moment, I think I didn’t implement “getOwnPropertyDescriptor” property and GOJS requires it (I’m quite clueless as to what getOwnPropertyDescriptor is…to be honest). Anyway of fixing it? When i insepected the data element when the Graph element is dragged onto the Stage, it incidentally produces an actual extra string property called “obj.name”:xxxx inside the object based on the console.log trace, instead of only setting { obj:{name:xxxx} }. I dunno why…
https://jsfiddle.net/L08qddog/5/