2014-10-01 40 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