0

In the handlebar template file where content is elements of the map:

map {<"1" -> [{:a => "1",:b => "as"},{:a => "2", :b => "hj"}]>,<"4" -> [{:a => "we",:b => "kj"}]>,......}

I want to know how to iterate over the elements of all structures of each list for each key of the map inside handlebar file

EDIT

{{# each content}}
  key: {{@key}} value = {{this}}
  ....
{{/each}}

value is list of structures. I want to iterate over the items in each structure in the list how to do that

sb15
  • 313
  • 5
  • 18

1 Answers1

0

You should definitely check the handlebars documentation first.

You can pass a whole Map into your HTML and then iterate and use your helper (aCustomHelper). The '@key' keyword refers to the key of the map and the 'this' keyword refers to the value of the map (example-map-object).

{{#each example-map-object}}
    <tr>
        <td>{{{this}}}</td>
        <td>{{{@key}}}</td>
        <td>{{{aCustomHelper @key this}}}</td>
    </tr>
{{/each}}

In the example below, you can see how you can access a Set object by key and value:

<select>
    {{#each example-set-object}}
          <option value="{{@value}}">{{@key}}</option>
    {{/each}}
</select>

In the example below, you can see how you can access a Map by it's key values, which is very handy indeed:

{{#each example-map-object}}
    <tr>
        <td>{{{this.id}}}</td>
        <td>{{{this.customerName}}}</td>
        <td>{{{this.date}}}</td>
    </tr>
{{/each}}

So the answer to your question is that YES, you can most certainly do what you want and pass the whole map as a parameter to your helper method.

{{yourHelper example-map-object}}
Bouramas
  • 1,077
  • 1
  • 17
  • 36