ember.js 如何将输入数据从模板传递到ember中的组件类?

p1tboqfb  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(132)

我正在尝试将输入字段中的数据传递给组件类
这是我的 * 组件类*alpha.js

@tracked choice;

    @action next() {

        console.log(this.choice);
    }

这是我的 * 模板*alpha.hbs

<Input @value={{this.choice}} type="radio"  />
    <button onclick={{action 'next'}}>Next</button>

到目前为止,它是空返回的。
任何帮助都将不胜感激。谢谢

dphi5xsq

dphi5xsq1#

<Input组件是为文本输入设计的。对于单选按钮,你需要做一些手工操作。一个简单的方法如下所示:

<input value="one" type="radio" {{on "change" this.change}} />
<input value="two" type="radio" {{on "change" this.change}} />
<button onclick={{action 'next'}}>Next</button>

使用此change操作:

@action change(event) {
  this.choice = event.target.value;
}

相关问题