如何在Ember中选择默认单选按钮

How do you select a default radio button in Ember?

本文关键字:选择 默认 单选按钮 Ember      更新时间:2023-09-26
{{input type="radio" name="customerFacing" value=report.customerFacing id="customerFacingYes" change=(action "customerFacingChange" "yes")}}<label for="customerFacingYes">Yes</label>

如果变量"report.customerFaceing"为true或false,我将尝试将单选按钮设置为选中。有什么可以用javascript编写的东西来将其设置为选中的吗?

感谢

您的代码将适用于复选框。

{{input type="checkbox" name="customerFacing"  checked=report.customerFacing value=report.customerFacing id="customerFacingYes" on-change=(action (mut report.customerFacingChange) checked)}} 
<label for="customerFacingYes">{{report.customerFacing}}</label>

但对于单选按钮,你可以试试addon。(https://github.com/yapplabs/ember-radio-button)

ember install ember-radio-button
{{#radio-button value=report.customerFacing groupValue=report.customerFacing class="cpntr" changed=(action "customerFacingChange")}}
      <label for="customerFacingYes">{{report.customerFacing}}</label>
 {{/radio-button}}

在控制器或任何其他地方,

actions: {
 customerFacingChange(newValue){
  console.log('Changed value'+newValue); //you can do other stuff here.
 }
}