Go 模板:如何访问模板中的数组项 (arr[2])?
Go templates: How do I access array item (arr[2]) in templates?
如何访问模板中的数组项(例如 a[2])?
每当我这样做时,我都会得到 "bad character U+005B '['"
{{ .a[2] }}
您需要使用index
模板函数。
{{index .a 2}}
以 *.yaml 格式访问数组项上的字段:
{{ (index .Values.fields 0).fieldItem }}
零索引 (0) 作为字段的字段数组作为 fieldItem。
如何访问模板中的数组项(例如 a[2])?
每当我这样做时,我都会得到 "bad character U+005B '['"
{{ .a[2] }}
您需要使用index
模板函数。
{{index .a 2}}
以 *.yaml 格式访问数组项上的字段:
{{ (index .Values.fields 0).fieldItem }}
零索引 (0) 作为字段的字段数组作为 fieldItem。