问题
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