如何扩展TextField以访问Ember.js中的模型

如何扩展TextField以访问Ember.js中的模型,ember.js,Ember.js,我正在用ember.js写一个表单帖子 attr绑定和条件仅支持布尔值,而不支持表达式 行动不需要争论 我希望仅当输入获得焦点且输入有效时才显示错误 简单地说,我应该在FocusIn和FocusOut属性中这样做。但是有这么多字段,我必须为每个输入写两个动作 我想编写一个可重用视图来实现这一点,但我不知道如何更改视图中模型的值 有人知道吗 Erp.FromFieldView = Ember.TextField.extend({ attributeBindings: ['type',

我正在用ember.js写一个表单帖子

  • attr绑定和条件仅支持布尔值,而不支持表达式
  • 行动不需要争论
我希望仅当输入获得焦点且输入有效时才显示错误

简单地说,我应该在FocusIn和FocusOut属性中这样做。但是有这么多字段,我必须为每个输入写两个动作

我想编写一个可重用视图来实现这一点,但我不知道如何更改视图中模型的值

有人知道吗

Erp.FromFieldView = Ember.TextField.extend({

    attributeBindings: ['type', 'value', 'size', 'pattern', 'name', 'min', 'max',
                      'accept', 'autocomplete', 'autosave', 'formaction',
                      'formenctype', 'formmethod', 'formnovalidate', 'formtarget',
                      'height', 'inputmode', 'list', 'multiple', 'pattern', 'step',
                      'width', 'error', 'regex'],
    name: 'default',

    error: '',

    regex: '^.+$',

    isValid: true,


    valueChanged: function () {
        re = new RegExp(this.get('regex'), 'g');
        this.set('error', !re.test(this.get('value')));
    }.observes('value'),

    focusIn: function (event) {
        this._super(event);
        if (this.get('value') == undefined) {
            this.set('error', true);
        }
    },

    focusOut: function (event) {
        this._super(event);
        this.set('error', false);
    }
});

Ember.Handlebars.helper('form-field', Erp.FromFieldView);