如何将布尔值绑定到单选按钮使用Aurelia
问题描述:
在我的方案中,我必须将从页面加载的数据库获得的布尔值绑定到一组单选按钮。如果属性的值为true,则应检查单选按钮。该组件的HTML像下面如何将布尔值绑定到单选按钮使用Aurelia
<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;
}
即使选项。响应属性是真实的,其他单选按钮正在检查。
在此先感谢
答
你不需要OptionUpdate
。它更简单。我创建了一个GistRun帮助您与单选按钮从数据对象从数据库:
是你能把这个解决了吗? – LStarky