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

前端 未结 9 1011
逝去的感伤
逝去的感伤 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:13

    I solved this issue for myself by adding a short script tag to the bottom of my handlebars code!

    Add a class to wherever you are calling @index and then the below jQuery code works (can also be done using vanilla JS).

    {{@index}}

    edit 4/28- This has changed to use vanilla JS for better backwards compatibility (i.e. IE7, 8):

    
    
    

    document.querySelectorAll has great compatibility but could also be document.getElementsByClassName("create_index")

提交回复
热议问题