仅为列表中的一个元素显示标记。 ember.js。(隐形收藏,话语)

时间:2017-04-21 15:41:05

标签: ember.js discourse

我有一个源代码(话语),而不是我需要使用ember.js。我正在尝试只处理一个" post" (第一个)使用cloaked-collection列表。

//topics.hbs
    {{#unless model.postStream.loadingFilter}}
            {{cloaked-collection itemViewClass="post"
                                 defaultHeight="200"
                                 content=postsToRender
                                 slackRatio="15"
                                 loadingHTML=""
                                 preservesContext="true"
                                 uncloakDefault="true"
                                 offsetFixedTop="header"
                                 offsetFixedBottom="#reply-control"}}
          {{/unless}}
//post.hbs
//some code here. 
//Then I want to insert <div class="uniw"></div> only on the first post

问题是:对于itemViewClass="post"的列表,如何检查我是否在第一个&#34;帖子&#34;?所以我可以插入一个代码。

1 个答案:

答案 0 :(得分:1)

您应该能够使用firstObject来获取集合的第一个对象。像这样:

{{items.firstObject}}

在每个区块内,您可以查看索引:

{{#each people as |person index|}}
  {{#if (is-equal index 0)}}
    {{person}}
  {{/if}}
{{/each}}

请注意,is-equal是非标准助手。您可以从ember-truth-helpers插件获取或自行编写