簡體   English   中英

如果循環不是數組中的最后一項,是否可以使用車把模板來呈現邏輯?

[英]Using handlebars templates is there a way to render logic if looping over not the last item in an array?

使用 java handlebars 4.2.1 https://github.com/jknack/handlebars.java如果循環不是數組中的最后一項,是否有渲染邏輯的方法?

我知道我可以這樣做:

{{#myArray}}
{{#if @last}}
{{else}}
  my rendered logic here
{{/if}}
{{/myArray}}

但我正在尋找只有一個塊的東西,類似於小胡子模板中的{{^-last}}

看起來可以使用 unless 助手來做到這一點:

{{#myArray}}
{{#unless @last}}
  my rendered logic here
{{/unless}}
{{/myArray}}

根據他們的文檔You can use the unless helper as the inverse of the if helper. Its block will be rendered if the expression returns a falsy value. You can use the unless helper as the inverse of the if helper. Its block will be rendered if the expression returns a falsy value.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM