In Mustache, How to get the index of the current Section

前端 未结 13 1079
臣服心动
臣服心动 2020-12-13 03:52

I am using Mustache and using the data

{ \"names\": [ {\"name\":\"John\"}, {\"name\":\"Mary\"} ] }

My mustache template is:



        
13条回答
  •  死守一世寂寞
    2020-12-13 04:18

    For reference, this functionality is now built in to Handlebars which has compatibility with Mustache.

    Use {{@index}}

    {{#names}}
        {{name}} is {{@index}}
    {{/names}}
    

    John is 0

    Mary is 1

提交回复
热议问题