gpt4 book ai didi

html - 从范围中获取索引号

转载 作者:IT王子 更新时间:2023-10-29 01:04:08 27 4
gpt4 key购买 nike

在获取索引号的php中:

foreach much as index => each{
//get index number from index
}

go中如何获取索引号?

{{ range .post }}
{{ // how can i get index number? }}
{{ .Id }}
{{ .Name}}
{{ end}}

最佳答案

text/template Variables:

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com