我在這里閱讀了很多與 Go 模板相關的帖子,但找不到我要找的內容。我有這兩個結構,我無法更改它們,因為它們在我正在幫助的項目的其他地方使用:type Schedule struct { Description string ControlNights int PlayNights int StartDay int Combos []Combo}type Combo struct { From time.Time Every int Until time.Time Sounds []string Volumes []int Waits []int}我需要在 html 頁面上顯示這些數據。所以我需要迭代每個 Combo。我可以做到這一點,但我需要將聲音、音量和等待放在一起,即聲音 x 音量 y 等待 z。其中 x、y 和 z 是 Sounds、Volumes 和 Waits 數組中的值。這些數組可以是 >= 1 的任意長度,但它們都具有相同的長度。我希望它看起來像這樣:
1 回答

達令說
TA貢獻1821條經驗 獲得超6個贊
如果您確定這三個數組具有相同數量的元素,那么您可以這樣做:
{{ $volumes := .Volumes }}
{{ $waits := .Waits }}
{{range $index,$sound := .Sounds }}
Print Sounds[i] like this: {{$sound}}
Print volumes[i] like this: {{index $volumes $index}}
Print waits[i] like this: {{index $waits $index}}
{{end}}
這應該會給你一個想法。
- 1 回答
- 0 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消