ember.js - Ember TextField valueBinding with dynamic property -


i'm trying write generic view handles custom fields in app, i'm having hard time getting work. here's scenario - have fielddef object defines custom fields, , valueobject has array, customfields, has values. i'm trying this:

{{view ember.textfield valuebinding="valueobject.customfields.[fielddef.name]"}} 

obviously doesn't work because treats fielddef.name literal. i've tried overriding textfield class, can't seem bind.

any suggestions on how accomplish this?

thanks, scott

ember can't bind array index, you'll have work around it. 1 solution limit one-way binding, textfield updates values hash. if you're planning submit form after user presses button, should trick.

define array of field ids in controller , hash values go in.

app.applicationcontroller = ember.controller.extend({   fieldids: ['name', 'email', 'whatever'],   fieldvalues: {} // {name: 'user', email: 'user@...', ...} }); 

now extend ember.textfield update values hash when text field changes. you'll need pass each instance fieldid , reference values hash controller.

app.textfield = ember.textfield.extend({   fieldid: null,   values: null,    valuechange: function() {       var fieldid = this.get('fieldid');       var values = this.get('values');       if (values && fieldid) values[fieldid] = this.get('value');   }.observes('value') }); 

the template simple.

{{#each fieldid in fieldids}}   <label>{{fieldid}}</label>   {{view app.textfield fieldidbinding="fieldid" valuesbinding="fieldvalues"}}   <br/> {{/each}} 

here fleshed out in jsfiddle.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -