【问题标题】:Handlebars.js How to itarate through nested array using outer loop indexHandlebars.js 如何使用外循环索引遍历嵌套数组
【发布时间】:2017-03-10 07:13:45
【问题描述】:

嗨。我的 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 为空。为什么?

【问题讨论】:

    标签: handlebars.js nested-loops arrayiterator


    【解决方案1】:
    {{#each variants}}
      Index: {{@index}}
      {{#with (lookup segments @index}}
        {{value}}
      {{/with}}
    {{/each}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 2022-06-30
      • 2018-11-02
      相关资源
      最近更新 更多