conditional on last item in array using handlebars.js template

前端 未结 6 2039
我在风中等你
我在风中等你 2020-12-04 15:17

I am leveraging handlebars.js for my templating engine and am looking to make a conditional segment display only if it is the last item in array contained in the templates c

6条回答
  •  鱼传尺愫
    2020-12-04 16:06

    If you just try to handle the first item of the array, this may help

    {{#each data-source}}{{#if @index}},{{/if}}"{{this}}"{{/each}}

    @index is provided by the each helper and for the first item, it would be equal to zero and thus can be handled by the if helper.

提交回复
热议问题