2014-10-01 102 views

回答

42

您使用index功能:

{{index .Amap "key1"}} 

http://golang.org/pkg/text/template/

index 
    Returns the result of indexing its first argument by the 
    following arguments. Thus "index x 1 2 3" is, in Go syntax, 
    x[1][2][3]. Each indexed item must be a map, slice, or array. 
+0

这工作,我曾经尝试过,但用它与切片时,我还以为是用它与地图。 – 2014-10-01 23:15:24

+0

@KyleBrandt我写了答案,然后我实际上必须仔细检查以确保。 – OneOfOne 2014-10-01 23:18:21

+1

这是否在管道内工作?你可以举一个例子来说明如何使用它作为'{{template'name'how_to_index_here?}}的一部分'' – chakrit 2015-07-28 09:06:49