admin管理员组

文章数量:1289634

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>

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>
Share Improve this question edited Jan 8, 2013 at 16:15 Nonyck asked Jan 8, 2013 at 16:10 NonyckNonyck 6821 gold badge13 silver badges29 bronze badges 1
  • Can you explain what exactly isn't working? – Rahul Commented Jan 8, 2013 at 16:26
Add a ment  | 

2 Answers 2

Reset to default 10

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

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

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}}

本文标签: javascriptMeteor display array inside a collectionStack Overflow