ember.js:扩展 Ember.TextField 并且仅在输入键时更新值 属性

ember.js: extend Ember.TextField and only update value property on enter key

我想创建一个文本字段,就像使用输入助手的文本字段一样,只是它的行为略有不同:它不会更新它绑定到的 属性,直到按下回车键。我扩展了组件并尝试覆盖可能更新 属性 的函数:

InputTextSoftComponent = Ember.TextField.extend(
  keyPress:->
    console.log("keypress")
  propertyDidChange:->
    console.log('propChange')
  didInsertElement:->
    console.log('insert')
  modelChangedValue:->
    console.log('changeval')

)

该组件现在就像一个普通的文本字段一样工作,我对此感到惊喜

{{input-text-soft id="height-input" class="position-inputs" type="text" value=controller.activeRegion.width}}

但是,我无法阻止文本字段中的更改更新值目标。我怎样才能防止这种情况并实现一种软绑定,以便输入仅更新 属性 回车键?我正在寻找特定于 Ember CLI 和组件使用的解决方案。

创建一个不同的绑定属性。真实 属性 的别名。将您的文本字段绑定到 属性。仅当按下 enter 时才从别名更新真实的 属性。伪:

{{input-text-soft id="height-input" realValueBinding="controller.activeRegion.width" value=newWidth...}}

keyPress() {
  if (keyCode == xx)
     this.set('realValue', this.get('newWidth'))
}