Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在meteor中导航集合内的数组和嵌套模板_Meteor - Fatal编程技术网

在meteor中导航集合内的数组和嵌套模板

在meteor中导航集合内的数组和嵌套模板,meteor,Meteor,我正在玩meteor,并试图用它创建一个简单的测验应用程序。我已通过以下方式设置我的问题集合: {question: "Why did the chicken cross the road??", choices: ["To eat", "To die", "It depends", "There is no chicken"], correctAnswer:2, number : 1}, {question: "Who was the first man to step on moon's

我正在玩meteor,并试图用它创建一个简单的测验应用程序。我已通过以下方式设置我的问题集合:

{question: "Why did the chicken cross the road??", choices: ["To eat", "To die", "It depends", "There is no chicken"], correctAnswer:2, number : 1}, 
{question: "Who was the first man to step on moon's surface?", choices: ["Yo Yo Honey Singh", "Neil Armstrong", "Buzz Eldrin", "Rakesh Sharma"], correctAnswer:1, number : 2},       
{question: "Where is Timbuktu? ", choices: ["Asia", "There is no such place", "Africa", "Europe"], correctAnswer:2, number : 3}, 
{question: "Who said 'there is no pill'?", choices: ["Morpheus", "Mr. Anderson", "Neo", "Yoda"], correctAnswer:0, number : 4}, 
{question: "What is the one thing that saved Arthur Dent's life multiple times?", choices: ["The bugblatter beast of Tral", "Ford Perfect", "A towel", "The babel fish"], correctAnswer:2 , number : 5}
我能够从集合中获取问题,但难以获取每个问题的选项(如上图所示存储在数组中)。我创建了两个模板,一个用于题干,另一个用于选项。选项模板嵌套在问题模板中,如下所示:

<template name="question">
  <p>{{ currentQuestion.question }}</p>
    <form>
      {{ #each currentQuestion.choices }}
      <div class="radio answers">
        {{> choices}}
     </div>
     {{ /each }}
    </form>
  </p>
</template>
<template name="choices">
    <input type="radio" name="answer" id="{{ choice }}"><label for="{{ choice }}">{{ choice }}</label><br>
</template>

{{currentQuestion.question}

{{{每个currentQuestion.choices} {{>选择} {{/每个}}

{{choice}}
显然,这是行不通的。现在我的问题是:

  • 这是设置问题集合的最佳方法吗
  • 如何设置嵌套模板以导航和显示集合中的选项数组
提前谢谢。期待着一些解决方案

干杯。


<template name="questions">
   {{#each questions}}
      {{> question}}
   {{/each}}
</template>

<template name="question">
    <p>{{ question }}</p>
    <form>
      {{ #each choices }}
        <div class="radio answers">
          {{> choices}}
        </div>
      {{ /each }}
    </form>
</template>

<template name="choices">
    <input type="radio" name="answer" id="{{ this }}"><label for="{{ this }}">{{ this }}</label><br>
</template>
{{{每个问题} {{>问题} {{/每个}} {{问题}

{{{#每个选项} {{>选择} {{/每个}} {{this}}}

好极了。这非常有效,作为额外的奖励,我发现了Meteopad。谢谢。