In to get the index number php:
foreach much as index => each{
//get index number from index
}
How can I get the index number in go?
{{ range .post }}
{{ // how can i get index number? }}
{{ .Id }}
{{ .Name}}
{{ end}}
In to get the index number php:
foreach much as index => each{
//get index number from index
}
How can I get the index number in go?
{{ range .post }}
{{ // how can i get index number? }}
{{ .Id }}
{{ .Name}}
{{ end}}
If a "range" action initializes a variable, the variable is set to the successive elements of the iteration. Also, a "range" may declare two variables, separated by a comma:
range $index, $element := pipeline
So in your example:
{{ range $i, $e := .post }}
Index: {{ $i }}
{{ .Id }}
{{ .Name}}
{{ end}}
© 2022 - 2024 — McMap. All rights reserved.