车把计数器#each [英] Counter for handlebars #each
问题描述
$ b $
<$>在Handlebars中,假设我有一个名字集合
c $ c $> {{#每个姓名}}
{{职位}}
{{姓名}}
{{/每个}}
其中{{position}}为第一个名字为1,第二个名字为2等。我是否必须将位置存储为键集合?
您可以使用内置Handlebars @index表示法完成此操作:
{{#each array}}
{{@index}}:{{this}}
{{/ each}}
@index将给出给定数组中每个项目的(从零开始)索引。
请注意,对于使用带有Razor视图引擎的Handlebars的用户,您必须使用符号@@ index来避免编译错误。
有关更多内置帮助程序,请参阅 http://handlebarsjs.com/
In Handlebars, say i have a collection of names
how can i do
{{#each names}}
{{position}}
{{name}}
{{/each}}
where {{position}} is 1 for the first name, 2 for the second name etc. Do I absolutely have to store the position as a key in the collection?
You can do this with the built-in Handlebars @index notation:
{{#each array}}
{{@index}}: {{this}}
{{/each}}
@index will give the (zero-based) index of each item in the given array.
Please note for people using Handlebars with the Razor view engine you must use the notation @@index to avoid compilation errors.
For more built-in helpers see http://handlebarsjs.com/
这篇关于车把计数器#each的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!