每个#和每个handlbars之外的变量 [英] Variables outside of #each with handlbars

查看:160
本文介绍了每个#和每个handlbars之外的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据,

I have the data,

data = {
  "items":  [
      {"value": "New", "id": 1},
      {"value": "Open", "id": 2},
      {"value": "Close", "id": 3}
    ],
  "current": 2
}

我是我的模板,我循环遍历项目,但想在循环中访问当前值。

I'm my template I loop through items, but want to access the current value while in the loop.

这不起作用,

{{#each items}}
    {{id}} - {{value}} - {{current}} 
{{/each}}


推荐答案

href =http://handlebarsjs.com/#paths =nofollow>精细的手册:

From the fine manual:


嵌套handlebars路径也可以包含 ../ 段,它们根据父上下文评估路径。

Nested handlebars paths can also include ../ segments, which evaluate their paths against a parent context.

所以你想用 {{../ current}} 来存取 current的值在父上下文中。

So you want to use {{../current}} to access the value of current in the parent context.

演示: http://jsbin.com/iyofuq/1/edit

这篇关于每个#和每个handlbars之外的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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