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

Я пытаюсь установить переключатель в качестве выбранного, если переменная «report.customerFacing» является истиной или ложью. Есть ли что-то, что я мог бы написать в 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. 
} 
} 
Смежные вопросы