从 handlebars.js 中的部分访问父作用域
Accessing parent scope from partial in handlebars.js
如何从局部访问#each 父作用域?
主模板:
(out of each = {{index}})<br> {{!-- some index --}}
{{#each someItem}}
(in each, but not on partial = {{../index}}) {{!-- access to index from parent scope --}}
{{>part}}
{{/each}}
部分:
<div class="part">
(in partial: {{itemName}} - {{../index}}) {{!-- not working !!! --}}
</div>
这是有问题的 Fiddle:
http://jsfiddle.net/0o8jpxjh/
如果您遇到同样的问题,请检查您的车把版本。我将 handlebars 更新到 2.0 版本并仅使用 {{@root.index}}。
如何从局部访问#each 父作用域?
主模板:
(out of each = {{index}})<br> {{!-- some index --}}
{{#each someItem}}
(in each, but not on partial = {{../index}}) {{!-- access to index from parent scope --}}
{{>part}}
{{/each}}
部分:
<div class="part">
(in partial: {{itemName}} - {{../index}}) {{!-- not working !!! --}}
</div>
这是有问题的 Fiddle: http://jsfiddle.net/0o8jpxjh/
如果您遇到同样的问题,请检查您的车把版本。我将 handlebars 更新到 2.0 版本并仅使用 {{@root.index}}。