我如何遍历字符串数组与流星Spacebars {{#each}}块? [英] How do I iterate over an array of Strings with the Meteor Spacebars {{#each}} block?

查看:125
本文介绍了我如何遍历字符串数组与流星Spacebars {{#each}}块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个持有问题对象Mongo.Collection。每一个问题有一个叫做物业选择

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. =)

推荐答案

看起来这是在评论解决,但只是让这个问题有一个答案:你应该使用这个在目前的情况下是一个基本的情况。

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>

这篇关于我如何遍历字符串数组与流星Spacebars {{#each}}块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆