我有一个包含“问题”对象的 Mongo.Collection。每个“问题”都有一个名为 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()
});
在我的模板中我有这个:
<div class="question">
<div class="question-content">
<p>{{text}}</p>
<ul>
{{#each choices}}
//?????????
{{/each}}
</ul>
</div>
</div>
我应该用什么代替问号,以便使用包含适当选项的列表项来流行无序列表?
感谢阅读。对不起,如果这很容易。我对 Meteor 还是有点菜鸟。 =)
最佳答案
看起来这在评论中已得到解决,但只是为了让这个问题有答案:在当前上下文是原始上下文的情况下,您应该使用 this
。
<div class="question">
<div class="question-content">
<p>{{text}}</p>
<ul>
{{#each choices}}
<li>{{this}}</li>
{{/each}}
</ul>
</div>
</div>
关于javascript - 如何使用 Meteor Spacebars {{#each}} block 迭代字符串数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31282522/