在Mustache中,如何获取当前Section的索引 [英] In Mustache, How to get the index of the current Section

查看:91
本文介绍了在Mustache中,如何获取当前Section的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用胡子并使用数据

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

我的胡子模板是:

{{#names}}
    {{name}}
{{/names}}

我想要做的是获取数组中当前数字的索引.像这样:

What I want to be able to do is to get an index of the current number in the array. Something like:

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

并打印出来

John is 1
Mary is 2

有可能用Mustache来做到这一点吗?或带把手或其他扩展件?

Is it possible to get this with Mustache? or with Handlebars or another extension?

推荐答案

作为参考,此功能现已内置于与小胡子兼容的车把.

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

使用{{@index}}

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

约翰是0

玛丽是1

这篇关于在Mustache中,如何获取当前Section的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆