1

我已经为文本框创建了组件,在这里我遇到了焦点输出触发器没有发生。如何从组件触发事件?

第 1 步创建文本框组件

文本框.hbs

{{input
      type=type
      value=amountValue
      placeholder=placeholder
      focus-out=focusouttrigger
}}

我在下面的代码中编写的脚本中的第 2 步

export default Component.extend({
  amountValue: null,
  didReceiveAttrs: function() {
    this._super(...arguments);
    let amountValue = this.get('amountValue');
    this.setProperties({
      amountValue: this.get('amountValue'),
      type: this.get('type'),
      placeholder: this.get('placeholder'),
      focusOutInput: this.get('focusOutInput')
    });

  },
  actions: {
    focusouttrigger: function() {
      console.log("working");
    }
  }

3)主页我在主页中添加了以下代码

<S2bText
     @type='text'
     @amountValue='1000'
     @placeholder="Enter the Amount"
     @focusOutInput = "focusouttrigger" />
4

1 回答 1

0

需要改变几件事才能使这项工作:

如果动作focusouttrigger存在呈现的组件中,{{input}}那么您需要使用帮助器将其传递给输入,{{action}}如下所示:

{{input focus-out=(action "focusouttrigger") }}

如果您将操作传递给呈现的组件,{{input}}那么您需要通过属性的名称来引用它(并且还使用操作帮助器):

<YourComponent @focusOutInput={{action "focusouttrigger"}} />

然后当你渲染{{input}}

{{input focus-out=@focusOutInput }}

这里有一个 twiddle 演示了这两个:twiddle(焦点输出操作记录到控制台)

于 2019-07-30T20:43:25.383 回答