[英]How to pass input data from template to the component class in ember?
I am trying to pass the data which is in the input field to the component class我正在尝试将输入字段中的数据传递给组件类
This is my component-class alpha.js这是我的组件类alpha.js
@tracked choice;
@action next() {
console.log(this.choice);
}
This is my template alpha.hbs这是我的模板alpha.hbs
<Input @value={{this.choice}} type="radio" />
<button onclick={{action 'next'}}>Next</button>
So far it is returning empty.到目前为止,它返回的是空的。
Any help would be appreciated.任何帮助,将不胜感激。 Thanks
谢谢
The <Input
component is designed to text inputs. <Input
组件设计用于文本输入。 For radio buttons you need to do some manual work.对于单选按钮,您需要做一些手动工作。 A simple approach could look like this:
一个简单的方法可能如下所示:
<input value="one" type="radio" {{on "change" this.change}} />
<input value="two" type="radio" {{on "change" this.change}} />
<button onclick={{action 'next'}}>Next</button>
With this change
action:通过此
change
操作:
@action change(event) {
this.choice = event.target.value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.