简体   繁体   English

在车把模板文件中访问地图的值

[英]Accessing values of a map inside handlebar template file

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 我想遍历列表中每个结构中的项目,该如何做

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). 您可以将整个Map传递到HTML中,然后进行迭代并使用您的帮助器(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). “ @key”关键字指的是地图的键,“ this”关键字指的是地图的值(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: 在下面的示例中,您可以看到如何通过键和值访问Set对象:

<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}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM