Attaching Bindings Manually, Dynamically

I'm creating a form of input textfields dynamically based on the fields in a model. I've tried to dynamically set a bindings array but can't get it to work yet. Anything else I could try?

Comments

  • This is more or less what I've tried to create so far in JSFiddle. Per your example, I am now trying to create the bindings when the component is created.
    http://jsfiddle.net/PYb9b/26/
  • edited July 2014
    Hi there, it looks like there isn't any data in your fiddle. But beyond that, you need to update your override of "create" to be of this format:
    
    create : enyo.inherit(function(sup) {
        return function () {
    	sup.apply(this, arguments);
        };
    }),
    
  • Here is an updated example. How can I dynamically create bindings?
    http://jsfiddle.net/PYb9b/39/
  • Fixed a few things with your fiddle. You had some mismatched quotes in your binding declaration, and your reference to "this" in the function passed to your forEach call had a scope issue - in these instances you can wrap the function with an enyo.bindSafely to preserve the scope: http://jsfiddle.net/PYb9b/40/
  • Thank you so much, Aaron & Mikey. I've been working with Enyo for a few weeks. As part of a larger project, I'm working toward a Naked Objects oriented UI in Enyo. Dynamic binding to the models has been the only hurdle so far. Thanks again.
  • A slightly more terse form is the binding() method added by enyo.BindingSupport.
    
    this.binding({
        from : '.model.' + key,
        to : ".$." + key + ".value"
    });
    
Sign In or Register to comment.