我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

获取范围内的索引号

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}}

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

So in your example:

{{ range $i, $e := .post }}
   Index: {{ $i }}
   {{ .Id }}
   {{ .Name}}
{{ end}}

近期文章

  • 所有N个的k个组合数
  • Go中定义的io库在哪里?
  • 在C程序中使用golang函数
  • 我可以创建自己的根证书以用于与Go进行SSL连接吗? 这样安全吗?
  • 读取CSV文件时如何跳过第一行?
  • 具有通道参数的功能出现死锁
  • 为什么我在这个多阶段构建中的最终docker镜像这么大?
  • 仅使用Elasticsearch选择特定字段
  • 在Go中通过MQTT解除编组JSON对象
  • 如何在遵守接口上的golang CodeReviewComments规则的同时强制执行正确的构造?
  • 查询比较为空字段
  • docker-compose找不到软件包
  • 互斥体在goroutine之间修改的切片未显示正确的同步
  • 使用testify模拟的表驱动测试
  • 在Go中为变量分配类型
  • 在图片中添加空白区域
  • 如何反序列化Kubernetes YAML文件
  • 如何将切片的副本传递给函数?
  • 如何从Golang访问C指针数组
  • 在GO中从一个结构复制到另一个结构

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华