【发布时间】:2016-12-31 05:27:05
【问题描述】:
在我的场景中,我必须将在页面加载时从数据库中获取的布尔值绑定到一组单选按钮。如果该属性的值为 true,则应选中单选按钮。组件 html 如下所示
<template>
<div repeat.for="option of question.Options" class="row">
<template if.bind="question.QuestionTypeID == 2">
<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1" style="text-align: right;padding-right:0px;">
<input type="radio" name="${option.QuestionID}" id="${option.OptionID}" model.bind="option.Response" checked.bind="option.Response" click.delegate="OptionUpdate($event.target)" />
</div>
</template>
<div class="col-lg-11 col-md-11 col-sm-11 col-xs-11">
<label for="${option.OptionID}" innerhtml.bind="option.OptionDesc">
</label>
</div>
</div>
我在 option.Response 中绑定了布尔值 click.delegate 方法如下所示
OptionUpdate(element)
{
for(let option in this.question.Options)
{
if(element.id == this.question.Options[option].OptionID && element.checked)
{
this.question.Options[option].Response = this.question.Options[option].OptionID;
}
else{
this.question.Options[option].Response = undefined;
}
}
return element.checked;
}
即使 option.Response 属性为 true,也会检查其他单选按钮。
提前致谢
【问题讨论】:
-
你能解决这个问题吗?
标签: javascript aurelia