Adding values in a range loop inside of a golang template

时间:2018-09-18 19:54:24

标签: html arrays loops templates go

So I have an array with three objects

[ { id: 1, key: 20 }, { id: 2, key: 190 }, { id: 3, key: 10 } ]

and when I use a range loop for those objects, I want it to add the key value of the current object to the old value.

I tried doing {{ range array }}{{ .key }}{{end}}

but that always outputs 2019010 while I want it to output 220

How could I do that?

0 个答案:

没有答案