2016-12-30 143 views
2

在我的方案中,我必須將從頁面加載的數據庫獲得的布爾值綁定到一組單選按鈕。如果屬性的值爲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; 
} 

即使選項。響應屬性是真實的,其他單選按鈕正在檢查。

在此先感謝

+0

是你能把這個解決了嗎? – LStarky

回答