在获取索引号的php中:
foreach much as index => each{
//get index number from index
}
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
所以在你的例子中:
{{ range $i, $e := .post }}
Index: {{ $i }}
{{ .Id }}
{{ .Name}}
{{ end}}
关于html - 从范围中获取索引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52075151/