Questions tagged «go-templates»

2
遍历模板中的地图
我正在尝试显示健身课程清单(瑜伽,普拉提等)。对于每个班级类型,都有几个班级,因此我想将所有瑜伽班和所有普拉提班归为一组,依此类推。 我做了这个功能来切片并绘制它的地图 func groupClasses(classes []entities.Class) map[string][]entities.Class { classMap := make(map[string][]entities.Class) for _, class := range classes { classMap[class.ClassType.Name] = append(classMap[class.ClassType.Name], class) } return classMap } 现在的问题是,根据http://golang.org/pkg/text/template/,我该如何遍历它,您需要以.Key格式访问它,我不知道键(除非我也传递了一个切片模板中的键数)。如何在我的视图中解包此地图。 我目前所拥有的是 {{ . }} 显示如下: map[Pilates:[{102 PILATES ~/mobifit/video/ocen.mpg 169 40 2014-05-03 23:12:12 +0000 UTC 2014-05-03 23:12:12 +0000 UTC 1899-12-30 00:00:00 +0000 UTC {PILATES Pilates …
91 go  go-templates 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.