【问题标题】:EmberJS. How use two way binding for input and focus event?EmberJS。如何使用两种方式绑定输入和焦点事件?
【发布时间】:2016-09-30 04:46:51
【问题描述】:

我正在尝试创建自定义输入组件。 首先,我尝试使用本机输入组件。像这样的

<input type="text" value="{{inputValue}}" onblur={{action "toggleInputFocused"}} onfocus={{action "toggleInputFocused"}}>

但此代码不提供双向绑定。观察者 valueChanged 未触发

valueChanged: Ember.observer('inputValue', function () {
  // deal with the change
  this.set("valueSet",(this.get('inputValue').trim().length > 0));
}),

后来我尝试使用输入助手

{{input value=inputValue focus=(action "toggleInputFocused")}}

在这种情况下 valueChanged 观察者被触发但焦点事件不监听,否则按键被触发。

如何同时使用两种方式绑定和焦点事件?

【问题讨论】:

    标签: ember.js binding


    【解决方案1】:

    没有用于 ember 的 focus 内置事件。但是有foucsInfocusOut
    事件列表https://guides.emberjs.com/v2.1.0/components/handling-events/#toc_event-names

    {{input value=inputValue focus-in="toggleInputFocused"}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-27
      • 1970-01-01
      相关资源
      最近更新 更多