问题
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. =)
回答1:
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>
来源:https://stackoverflow.com/questions/31282522/how-do-i-iterate-over-an-array-of-strings-with-the-meteor-spacebars-each-bl