Iterating through map in template

前端 未结 2 1210
名媛妹妹
名媛妹妹 2020-12-23 14:04

I am trying to display a list gym classes (Yoga, Pilates etc). For each class type there are several classes, so I want to group all the Yoga classes, and all the Pilates cl

2条回答
  •  一生所求
    2020-12-23 14:59

    Check the Variables section in the Go template docs. A range may declare two variables, separated by a comma. The following should work:

    {{ range $key, $value := . }}
       
  • {{ $key }}: {{ $value }}
  • {{ end }}

提交回复
热议问题