简体   繁体   English

从handlebars.js中的局部访问父作用域

[英]Accessing parent scope from partial in handlebars.js

How to access #each parent scope from partial? 如何从局部访问#each父范围?

Main template: 主模板:

(out of each = {{index}})<br>            {{!-- some index --}}
{{#each someItem}}
(in each, but not on partial = {{../index}}) {{!-- access to index from parent scope --}}
  {{>part}}
{{/each}}

Partial: 部分:

<div class="part">
  (in partial: {{itemName}} - {{../index}})     {{!-- not working !!! --}}
</div>

Here is the Fiddle with problem: http://jsfiddle.net/0o8jpxjh/ 这是有问题的小提琴: http : //jsfiddle.net/0o8jpxjh/

If you had the same problem, check your handlebars version. 如果您遇到相同的问题,请检查您的车把版本。 I updated handlebars to 2.0 version and just use {{@root.index}}. 我将车把更新为2.0版本,仅使用{{@ root.index}}。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM