Using Ember.js text field ids for a

后端 未结 3 2163
再見小時候
再見小時候 2020-12-15 19:13

A label tag is of the form:

W

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 19:42

    Here was my solution to this problem from a while back:

    App.Widget.TextField = Em.ContainerView.extend({
        tagName: '',
        type: 'text',
        label: null,
        value: null,
        valueSize: '30px',
    
        childViews: ['labelView', 'inputView'],
    
        labelView: Em.View.extend({
            tagName: 'label',
            attributeBindings: ['for'],
    
            forBinding: 'parentView.inputView.elementId',
    
            init: function () {
                this.set('defaultTemplate', Em.Handlebars.compile(this.getPath('parentView.label')));
                this._super();
            }
        }),
    
        inputView: Em.TextField.extend({
            typeBinding: 'parentView.type',
            sizeBinding: 'parentView.valueSize',
            valueBinding: 'parentView.value'
        })
    });
    

    Then from within a Handlebars template:

    {{view App.Widget.TextField label="Some Label"}}
    

提交回复
热议问题