Handlebars.js 如何使用外循环索引遍历嵌套数组
Handlebars.js How to itarate through nested array using outer loop index
你好。我的 JSON 是:
variants : [
{
name : "one",
segments : [
{ value : 1 },
{ value : 2 },
{ value : 3 }
]
},
{
name : "two",
segments : [
{ value : 4 },
{ value : 5 },
{ value : 6 }
]
}
]
{{#each variants}}
Index: {{@index}}
Value: {{segments.[@index].value}}
{{/each}}
我希望值输出为 1 和 5。
Index 不为空,但 Value 为空。为什么?
{{#each variants}}
Index: {{@index}}
{{#with (lookup segments @index}}
{{value}}
{{/with}}
{{/each}}
你好。我的 JSON 是:
variants : [
{
name : "one",
segments : [
{ value : 1 },
{ value : 2 },
{ value : 3 }
]
},
{
name : "two",
segments : [
{ value : 4 },
{ value : 5 },
{ value : 6 }
]
}
]
{{#each variants}}
Index: {{@index}}
Value: {{segments.[@index].value}}
{{/each}}
我希望值输出为 1 和 5。 Index 不为空,但 Value 为空。为什么?
{{#each variants}}
Index: {{@index}}
{{#with (lookup segments @index}}
{{value}}
{{/with}}
{{/each}}