首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果循环遍历的不是数组中的最后一项,有没有办法使用handlebars模板来呈现逻辑?

如果循环遍历的不是数组中的最后一项,有没有办法使用handlebars模板来呈现逻辑?
EN

Stack Overflow用户
提问于 2021-10-03 18:39:33
回答 1查看 17关注 0票数 0

如果循环遍历的不是数组中的最后一项,那么使用java handlebars 4.2.1 https://github.com/jknack/handlebars.java有没有一种呈现逻辑的方法?

我知道我可以做到:

代码语言:javascript
复制
{{#myArray}}
{{#if @last}}
{{else}}
  my rendered logic here
{{/if}}
{{/myArray}}

但我正在寻找只有一个块的东西,类似于胡子模板中的{{^-last}}

EN

回答 1

Stack Overflow用户

发布于 2021-10-03 18:42:24

看起来人们可以使用除非帮助器来做这件事:

代码语言:javascript
复制
{{#myArray}}
{{#unless @last}}
  my rendered logic here
{{/unless}}
{{/myArray}}

每个their docs 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.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69427822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档