集合内的流星显示数组

Meteor display array inside a collection

本文关键字:显示 数组 流星 集合      更新时间:2023-09-26

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

I tried this

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

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

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

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

这段代码不起作用:

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

因为这里的"tag"既指列表又指列表中的一个元素。试一试:

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