Complex two-way data binding

62 views
Skip to first unread message

g...@cfware.com

unread,
Jun 15, 2016, 10:11:03 AM6/15/16
to Polymer
Hello, I'm working on a web based administration application that needs some bindings that don't seem to be supported.  I've posted a live demo of the simplest test case at [1].  The goal is to be able to use two-way binding on the properties of obj.  In real life both properties arr and obj would be populated by iron-ajax.  This pattern would be fairly common in my app.  A real world example for using this pattern is to have a global array of groups into arr, and the membership of a single user in obj.  Merging the data from obj into arr would not be a good solution - it would be very wasteful to transmit 'arr' in every AJAX GET/POST.

I'm unsure if I really want a way to create two-level binding as proposed in the jsbin, or if I need a way to create a lookup property (with a getter and setter in code).

Arthur Evans

unread,
Jul 1, 2016, 1:28:55 PM7/1/16
to g...@cfware.com, Polymer
Hi,

I can't think of a direct way to do this except for merging the data on load, and splitting it when you save it. However, you can achieve the connection you want using a computed binding to set the value of the checkbox, and an event listener to handle the set case. There's an example here:


Note that the getValue method is fairly generic, since you path in the path to the object. It's a little harder to make the listener generic. But you could stick a piece of data on the DOM node for the event handler to pick up. (Here's a version that does that, stowing the path as the `my-path` attribute on the checkbox, so you could use the same generic function in different places. Whether or not this approach is useful to you would depend a lot on the structure of your app & data.


Hope that helps.
Arthur


Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/a55c420d-2685-4cee-8585-6877faff2be2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages