Handlebars.js:如何访问每个嵌套的父索引? [英] Handlebars.js: How to access parent index in nested each?

查看:69
本文介绍了Handlebars.js:如何访问每个嵌套的父索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何在每个循环中访问父级@index值?

p> {{#each company}}
{{#each employee}}
{{../@index}} //如何访问公司索引?
{{/ each}}
{{/ each}}

结果为错误:


期待'ID',得到'DATA'



解决方案

示例中存在语法错误。正确的语法是 {{@ .. / index}}



我们正在寻找可以在未来版本的语言中支持这些参数的自定义命名,因此更易于处理。
https://github.com/wycats/handlebars.js/issues/907


How to access parent @index value in each-loop?

Tried the following:

{{#each company}}
{{#each employee}}
  {{../@index}} // how to access company index here?
{{/each}}
{{/each}}

This results to an error:

Expecting 'ID', got 'DATA'

解决方案

There is a syntax error in the example. The correct syntax is {{@../index}}.

We are looking at ways that we can support custom naming of these parameters in future versions of the language so this is easier to deal with. https://github.com/wycats/handlebars.js/issues/907

这篇关于Handlebars.js:如何访问每个嵌套的父索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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