Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何访问模板中的数组项(例如 a[2])?
每当我这样做时,我都会得到“坏字符 U+005B '['”
{{ .a[2] }}
您需要使用index模板功能。
index
{{index .a 2}}
以 *.yaml 格式访问数组项上的字段:
{{ (index .Values.fields 0).fieldItem }}
零(0)的索引,如 field 的 fields 数组 fieldItem 。