javascript - Aurelia radio button binding - Stack Overflow

Hope someone can help me with this. I've got the following view:<label repeat.for="option

Hope someone can help me with this. I've got the following view:

<label repeat.for="option of options">
    <input type="radio" name="periodOptions" model.bind="option" checked.bind="$parent.selectedOption" click.delegate="clicked()"/>
    ${option.text}
</label>

and the following viewmodel:

export class PeriodPanel {
    heading = 'Tidsperiode';
    options = [];
    selectedOption = {};

    constructor() {
        this.options = [
            {id:1, text:'Vis med dagoppløsning'}, 
            {id:2, text:'Vis med timeoppløsning'}, 
            {id:3, text:'Vis periode'}
        ]; 
        this.selectedOption = this.options[0];
    }

    clicked() {
        console.log(this.selectedOption.id);
    }
}

The reason for the assignment this.selectedOption = this.options[0]; is to make sure that one of the radio buttons are initially set. This is all nice and dandy, but when I click on each radio button in turn, the value of the selectedOption variable does not change and the click-handler clicked() will print the value 1 each time. What am I doing wrong?

TIA

Hope someone can help me with this. I've got the following view:

<label repeat.for="option of options">
    <input type="radio" name="periodOptions" model.bind="option" checked.bind="$parent.selectedOption" click.delegate="clicked()"/>
    ${option.text}
</label>

and the following viewmodel:

export class PeriodPanel {
    heading = 'Tidsperiode';
    options = [];
    selectedOption = {};

    constructor() {
        this.options = [
            {id:1, text:'Vis med dagoppløsning'}, 
            {id:2, text:'Vis med timeoppløsning'}, 
            {id:3, text:'Vis periode'}
        ]; 
        this.selectedOption = this.options[0];
    }

    clicked() {
        console.log(this.selectedOption.id);
    }
}

The reason for the assignment this.selectedOption = this.options[0]; is to make sure that one of the radio buttons are initially set. This is all nice and dandy, but when I click on each radio button in turn, the value of the selectedOption variable does not change and the click-handler clicked() will print the value 1 each time. What am I doing wrong?

TIA

Share Improve this question edited Oct 12, 2016 at 22:44 Jeremy Danyow 26.4k12 gold badges90 silver badges135 bronze badges asked Feb 2, 2016 at 18:10 norgienorgie 5177 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Return true from your clicked() method to allow the event to propagate.

Here's a working example:

https://gist.run/?id=84eb0949ff63c3f10a1eff3c337f2c97

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742355606a4428368.html

相关推荐

  • javascript - Aurelia radio button binding - Stack Overflow

    Hope someone can help me with this. I've got the following view:<label repeat.for="option

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信