JavaScript对象数组中的多个字符串

时间:2018-11-11 12:56:55

标签: javascript

so id喜欢向此数组添加多个答案:

topojson-server

类似“ answer:“ a” ||“ aporo” 那可能吗? 任何答案都会非常感谢uwu

2 个答案:

答案 0 :(得分:1)

我会走另外一条路。

认为您的问题包含多个可能的答案,然后将其保存为这样。

考虑一个包含多个可能答案的问题,而不是标记为一个答案的1个问题。所以我会像这样建立它:

var questions = [
    {"question":"What is the maori translation for: \"Apple\"?", 
     "PossibleAnswers": 
      [{"text":"Aporo","correct":true},
        {"text":"Ako","correct":false},
        {"text":"Whanaunga","correct":false},
        {"text":"Pene rākau","correct":false}
      ]},
    {"question":"How many fingers on a hand?", 
     "PossibleAnswers": 
      [{"text":"3","correct":true},
        {"text":"5","correct":false},
        {"text":"10","correct":false},
        {"text":"4 and 1 thumb","correct":true}
      ]},
    {"question":"What is the maori translation for the french word: \"Pomme\"", 
     "PossibleAnswers": 
      [{"text":"Ako","correct":false},
        {"text":"Whanaunga","correct":false},
        {"text":"Aporo","correct":true},
        {"text":"Pene rākau","correct":false}
      ]}
]

通过这种方式,您既可以拥有多个正确答案,又可以更好地控制向受访者表达问题的方式。

答案 1 :(得分:0)

像这样吗?

var questions = [
    {"question":"Some question text1", "answers": ["answer 1", "answer 2"]},
    {"question":"Some question text2", "answers": ["answer 3", "answer 4"]},
    {"question":"Some question text3", "answers": ["answer 5", "answer 6"]}
]