Variables outside of #each with handlbars

我怕爱的太早我们不能终老 提交于 2019-12-13 04:56:29

问题


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.

This doesn't work,

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

回答1:


From the fine manual:

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

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

Demo: http://jsbin.com/iyofuq/1/edit



来源:https://stackoverflow.com/questions/13284141/variables-outside-of-each-with-handlbars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!