Quantcast
Viewing all articles
Browse latest Browse all 4827

How to show only one item out of many similar items in a template #each loop

@armikhalev wrote:

I have encountered a problem with filtering in templates when I'm trying to show items only once instead of repeating the same item, though coming as a different property. It is easier to show in code:

{{#each gCard as |card|}}
    Category: {{ card.category }}

    <ul>
        <li><b>{{ card.title }}</b></li>
        <li>{{ card.body }}</li>
        <li>{{ card.comment }}</li>
    </ul>

{{/each}}

This results in category header being repeated several times like this:

Category: first cat
title
body
comment

Category: first cat
title
body
comment

Category: second cat
title
body
comment

I don't want "first cat" to be repeated twice, only once, like this:

Category: first cat
title
body
comment

title
body
comment

Category: second cat
title
body
comment

Is it achievable within template or I should deal with data in controller? What would be the Ember way of solving this problem?

Thank you

Posts: 5

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4827

Trending Articles