[英]Go templates: How do I access array item (arr[2]) in templates?
如何訪問模板中的數組項(例如 a[2])?
每當我這樣做時,我都會得到“壞字符 U+005B '['”
{{ .a[2] }}
您需要使用index
模板功能。
{{index .a 2}}
以 *.yaml 格式訪問數組項上的字段作為模板:
{{ (index .Values.fields 0).fieldItem }}
零 (0) 的索引,如 field 的 fields 數組中的 fieldItem 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.