通过复选框检查多选问题的答案以显示正确的答案angularjs

时间:2019-06-27 08:20:32

标签: angularjs

我想通过检查是否选中了is_answer = 1来检查答案是否正确并显示正确的单词或是否显示错误

我在数组vm.quiz_multi_answer = []; vm.quiz_multi_answer.push();中返回答案 我想遍历所有选择,以将所选答案与is_answer

进行比较
vm.quiz_multi_data = [
    {
      question: "What does HTML stand for?",
      choices: [
        {
          id: "0",
          choice: "HyperText Markup Language",
          is_answer: "1"
        },
        {
          id: "1",
          choice: "HyperText Markup Language",
          is_answer: "1"
        },
        {
          id: "2",
          choice: "HyperText Markup Language",
          is_answer: "0"
        },
        {
          id: "3",
          choice: "HyperText Markup Language",
          is_answer: "0"
        }
      ]
    }
  ];

1 个答案:

答案 0 :(得分:0)

您可以像这样

for(let i =0  ;i < quiz_multi_data.length ; i ++ ){
 if(quiz_multi_data[i].question/_id == "any_question_veriable"){
    for(let j =0 ; j < quiz_multi_data[i].choices[j].length ; j++ ){
           if( quiz_multi_data[i].choices[j]._id == id){
              //perform some logic 
            }
    }
}