【问题标题】:Meteor display array inside a collection集合内的流星显示数组
【发布时间】:2013-01-08 16:10:19
【问题描述】:

我想创建一个带有标签的帖子模型,并且能够显示每个帖子的所有标签。你知道最好的方法吗??

我试过了

<template name='postsLists'>
  {{#each post}}
    {{> postDetails }}
  {{/each}}
</template>


<template name='postDetails'>
  title: {{title}}
  {{#each tag}}
    {{tag}}
  {{/each}}
</template>

【问题讨论】:

  • 你能解释一下到底是什么不工作吗?

标签: javascript model meteor


【解决方案1】:

您需要使用this 关键字从数组中获取值:

<template name='postDetails'>
  title: {{title}}
  {{#each tag}}
    {{this}}
  {{/each}}
</template>

【讨论】:

    【解决方案2】:

    此代码不起作用:

    {{#each tag}}
      {{tag}}
    {{/each}}
    

    因为这里的“标签”指的是列表和该列表中的元素。试试:

    {{#each tags}}
      {{tag}}
    {{/each}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 2019-08-30
      • 1970-01-01
      • 2016-02-27
      • 1970-01-01
      相关资源
      最近更新 更多