簡體   English   中英

html單選按鈕不可單擊(實際文件是玉)

[英]html radio button are not clickable (The actual file is jade)

這個問題會更容易一些,但我只能堅持一些小事情:我的棱角對象是這樣的:

$scope.questions = [
  {
    questionText: "1. This is a test question#1",
    choices: [{
            id: 1,
            text: "NO",
            isUserAnswer: false
        }, {
            id: 2,
            text: "YES",
            isUserAnswer: true
        }]
  },
  {
    questionText: "2. This is a test question#2",
    choices: [{
            id: 1,
            text: "NO",
            isUserAnswer: false
        }, {
            id: 2,
            text: "YES",
            isUserAnswer: true
        }]
  }
];

現在,我嘗試使用此對象填充前端(jade / html),以便為每個問題設置兩個單選按鈕。 我的翡翠文件是這樣的:

div
  ul.unstyled
    li(ng-repeat='question in questions')
      strong.question {{question.questionText}}
      ul.unstyled(id='quest_{{$parent.$index}}')
        li(ng-repeat='choice in question.choices')
          label.(class='isCorrect_{{choice.selected}}', for='quest_{{$parent.$index}}_choice_{{$index}}')
            input(type='radio', id='quest_{{$parent.index}}_choice_{{$index}}', ng-model='choices[$parent.$index]', value='{{choice.text}}', name='quest_{{$parent.$index}}_choices', ng-click='showResult()')
            |  {{choice.text}}

現在,我可以在html頁面上看到問題和單選按鈕,但是由於某種原因,我無法執行任何按鈕的單擊。 有明顯的原因嗎? 任何幫助,將不勝感激。 當我更改為html文件時,它可以完美工作。

這可能是由於您的ngModel定義:

ng-model='choices[$parent.$index]'

選擇未定義。 但是, question.choices是:

ng-model='question.choices[$parent.$index]'

但是,您似乎真正想要的是使用問題本身,而不是使用選擇作為模型。 並且,您需要在問題上使用新屬性, answer

ng-model='question.answer'

現在,做出選擇后,問題將具有帶有所選答案的值的answer屬性:

{
  questionText: "2. This is a test question#2",
  answer: "YES",
  choices: [{
        id: 1,
        text: "NO",
        isUserAnswer: false
    }, {
        id: 2,
        text: "YES",
        isUserAnswer: true
    }]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM