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

Ich versuche, das Optionsfeld als ausgewählt festzulegen, wenn eine Variable "report.customerFacing" wahr oder falsch ist. Kann ich etwas in Javascript schreiben, um es als ausgewählt zu setzen?Wie wählen Sie ein Standard-Optionsfeld in Ember?

Vielen Dank

+0

Sie haben eine eigene Komponente erstellen, bitte prüfe hier http://stackoverflow.com/questions/30244040/recording-values-of-radio-button-in-ember –

Antwort

0

Ihr Code wird für das Kontrollkästchen funktionieren.

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

Aber für den Radio-Button Sie Add-on versuchen. (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}} 

In Controller oder an jedem anderen Ort,

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