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

时间:2016-07-29 13:26:20

标签: javascript ember.js

{{input type="radio" name="customerFacing" value=report.customerFacing id="customerFacingYes" change=(action "customerFacingChange" "yes")}}<label for="customerFacingYes">Yes</label>

如果变量&#34; report.customerFacing&#34;,为true或false,我试图将单选按钮设置为选中状态。我可以用javascript写一些东西来设置它吗?

谢谢

1 个答案:

答案 0 :(得分:0)

您的代码适用于复选框。

{{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>

但是对于单选按钮,您可以尝试添加。(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.
 }
}
相关问题