2014-09-17 2 views
0

유성을 가지고 노는 중이고 동일한 것을 사용하여 간단한 퀴즈 응용 프로그램을 만들려고합니다.컬렉션 내의 배열 탐색 및 유성 템플릿 중첩 된 템플릿

{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> 

는 분명이 작동하지 않습니다. 이제 내 질문은 다음과 같습니다.

  • 질문 모음을 설치하는 가장 좋은 방법입니까?
  • 내 컬렉션의 선택 배열을 탐색하고 표시하도록 중첩 템플릿을 설정하려면 어떻게해야합니까?

미리 감사드립니다. 이를위한 몇 가지 솔루션을 기대합니다.

건배 ..

답변

1
<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> 

See working sample in meteorpad

+0

우수. 그것은 완벽하게 작동했고 추가 보너스로 나는 유성우를 발견했습니다. 고마워. –