Meteor display array inside a collection

巧了我就是萌 提交于 2019-12-30 09:35:56

问题


I want create a posts model, with tags, and be able to display all tags for each post. You know a best way to do it ??

I tried this

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


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

回答1:


You need to use this keyword to get value from an array:

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



回答2:


This code won't work:

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

because "tag" here refers to both the list and an element in that list. Try:

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


来源:https://stackoverflow.com/questions/14219222/meteor-display-array-inside-a-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!