如何访问模板中的数组项(例如 a[2])?
每当我这样做时,我都会收到“bad character U+005B '['”
{{ .a[2] }}
最佳答案
您需要使用index
模板函数。
{{index .a 2}}
关于templates - Go 模板 : How do I access array item (arr[2]) in templates?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31235211/