How to get an array value at index using Handlebars.js?

后端 未结 2 1474
小鲜肉
小鲜肉 2020-12-14 04:04

Say I have JSON:

{
userinput: [
    {name: \"brian\", \"value\": \"i like pies\"},
    {name: \"susan\", \"value\": \"memes are stupid\"}
],
feedback: [
             


        
2条回答
  •  一生所求
    2020-12-14 04:13

    This can be accomplished using the lookup helper:

    The lookup helper allows for dynamic parameter resolution using Handlebars variables. This is useful for resolving values for array indexes.

    So the template for your example would look like this:

    {{#each userinput}}
        {{name}}
        {{value}}
        
            {{#with (lookup ../feedback @index)}}
                {{value}}
            {{/with}}
        
    {{/each}}
    

提交回复
热议问题