How do I iterate over an array of Strings with the Meteor Spacebars {{#each}} block?

I have a Mongo.Collection that holds 'Question' objects. Each 'Question' has a property called choices

Questions.insert({
    text: 'What is the capitol of the US?',
    choices: [
    "Washington D.C.",
    "Houston",
    "New York City",
    "Los Angeles"
    ],
    correctChoice: 0,
    date: new Date().toDateString()
});

In my template I have this:

<div class="question">
    <div class="question-content">
        <p>{{text}}</p>
        <ul>
            {{#each choices}}
            //?????????
            {{/each}}
        </ul>
    </div>
</div>

What should I put instead of the question marks in order for popular the unordered list with list items that contain the appropriate choices?

Thank you for reading. Sorry if this is easy. I'm still a little bit of a noob at Meteor. =)

Answers:

Answer

It looks like this was solved in a comment, but just so this question has an answer: you should use this in cases where the current context is a primitive.

<div class="question">
  <div class="question-content">
    <p>{{text}}</p>
    <ul>
      {{#each choices}}
        <li>{{this}}</li>
      {{/each}}
    </ul>
  </div>
</div>

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.