2016-07-29 95 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. 
} 
}