在余烬车把中使用每个

问题描述 投票:0回答:2

我有如下所示的each循环,我想在第一个元素前添加'(',在最后一个元素后添加')'。有人可以帮我怎么做吗?任何帮助都将非常非常有帮助-谢谢

{{#each  v.NOVNoticeTypeName as |vv iindex|}}
    {{get v.NOVNoticeTypeName iindex}}: {{get v.NOVNumber iindex}}
    <br/>                                         
{{/each}}
javascript ember.js ember-cli
2个回答
1
投票

使用ember-truth-helpers只是检查元素是数组中的第一个元素还是最后一个元素(不确定要使用(和)做什么,所以我只是猜测:

{{#each  v.NOVNoticeTypeName as |vv iindex|}}
  {{#if (or (eq v.NOVNoticeTypeName.firstObject vv) (eq v.NOVNoticeTypeName.lastObject vv))}}
    ({{get v.NOVNoticeTypeName iindex}}: {{get v.NOVNumber iindex}})
  {{else}}
    {{get v.NOVNoticeTypeName iindex}}: {{get v.NOVNumber iindex}}
  {{/if}}
  <br/>                                         
{{/each}}

1
投票

我建议结合使用ember-truth-helpersember-composable-helpershas-nexthas-previous

{{#each v.NOVNoticeTypeName as |vv iindex|}}
  {{#if (not (has-previous vv v.NOVNoticeTypeName))}}
    {{!-- This is the first element in the array}} --}}
    ({{get v.NOVNoticeTypeName iindex}}: {{get v.NOVNumber iindex}}
  {{else if (not (has-next vv v.NOVNoticeTypeName))}}
    {{!-- This is the last element in the array}} --}}
    {{get v.NOVNoticeTypeName iindex}}: {{get v.NOVNumber iindex}})
  {{else}}
    {{!-- This is everything except the first and last element --}}
    {{get v.NOVNoticeTypeName iindex}}: {{get v.NOVNumber iindex}}
  {{/if}}
  <br />
{{/each}}
© www.soinside.com 2019 - 2024. All rights reserved.