templates - Go 模板 : How do I access array item (arr[2]) in templates?

标签 templates go beego

如何访问模板中的数组项(例如 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/

相关文章:

go - go++ 运算符需要互斥量吗?

去防止重复

c++ - std::abs 的模板版本

templates - Elasticsearch模板不读取参数

c++ - 使用基本模板标识符时继承

templates - 检查符号是否是 D 中的成员函数/字段的[指针]

go - 访问基本身份验证凭据

go - 类型转换接口(interface) slice

api - beego 更新 & 通过 ID 获取 1

go - 为什么我安装的 beego web 框架不起作用?