【发布时间】:2012-09-23 23:10:13
【问题描述】:
我有一片:Keys []* datastore.Key
如何在模板文件中索引其中之一?我猜到了{{.Keys[3] }},但这不起作用,我搜索了很多但没有任何线索。
欢迎任何建议,谢谢。
【问题讨论】:
标签: slice go-templates
我有一片:Keys []* datastore.Key
如何在模板文件中索引其中之一?我猜到了{{.Keys[3] }},但这不起作用,我搜索了很多但没有任何线索。
欢迎任何建议,谢谢。
【问题讨论】:
标签: slice go-templates
像这样使用index 命令:
{{index .Keys 3}}
【讨论】:
html/template 文档的概述:“有关如何对模板本身进行编程的信息,请参阅文本/模板的文档。”
如 html/template 包中所述,大多数示例实际上位于 text/template pkg 文档中。见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.
【讨论】: