Ember.js: TextField with dynamic binding

前端 未结 3 1348
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 05:22

I want to bind a TextField to a property which is specified by a string variable (see the edit for a better explanation), as in this question. Unfortunately the answer that was

3条回答
  •  醉梦人生
    2021-01-25 06:27

    After many failed attempts I found a pretty simple solution.

    Add the helper

    Ember.Handlebars.helper('dataTextField', function (data, key, options) {
        options.hash.valueBinding = 'data.' + key;
    
        return Ember.Handlebars.helpers.input.apply(this, [options]);
    });
    

    and then call

    {{dataTextField data key}}
    

    This will render a text field that shows and changes the value of data[key] and it even supports all the optional arguments the normal input helper can understand.

提交回复
热议问题