2016-07-29 62 views
2
{{input type="radio" name="customerFacing" value=report.customerFacing id="customerFacingYes" change=(action "customerFacingChange" "yes")}}<label for="customerFacingYes">Yes</label> 

我想将单选按钮设置为选中,如果变量“report.customerFacing”是true或false。有什么我可以写在JavaScript中设置为选中?如何选择Ember中的默认单选按钮?

谢谢

+0

你必须创建一个自定义组件,请在这里检查http://stackoverflow.com/questions/30244040/recording-values-of-radio-buttons-in-ember –

回答

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. 
} 
}