Adding offset to {{@index}} when looping through items in Handlebars

前端 未结 9 1022
逝去的感伤
逝去的感伤 2020-12-24 01:20

I\'m iterating over a list in Handlebars using the built-in each helper. Within the each block, I\'m referencing the current loop index

9条回答
  •  悲&欢浪女
    2020-12-24 02:03

    there is an easy way to incitement with the {{@index}} value.

    solution is to call the funtion and pass the @index value o it and than on JS, use helper to return @index + 1

    here is go

    {{incitement @index}}

    and here is code for the js

    Handlebars.registerHelper("incitement", function (inindex) {
      return inindex + 1
    });

提交回复
热议问题