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

如何从地图上获取钥匙

I'm working on go template. Having some map in . I know how to get the value, as long as I know the key.

"Map value: {{ printf "%s" .key1 }}"

How to get key name from inside the template? I would expect maybe something like

"Map key: {{ printf "%s" (keys .)[0] }}"

As @Adrian commented:

{{ range $key, $val := . }}
key: {{ $key }}; value: {{ $val }}
{{ end }}

But it was hard to figure it out just from range documentation

近期文章

  • 将打印语句重定向到文件
  • 读取可接受数据中的特定字节数
  • 用一组键拆分对象数组
  • 具有接口类型字段的结构
  • 从PHP运行Go脚本
  • 在Windows中构建GO程序
  • 从文件读取字节到内存
  • 在Go中解析时间戳
  • 在GO中运行python脚本
  • 去候车团没有明显的行为[重复]
  • SQLSERVER 表A某列数据插入B表
  • 处理字符串数组中的数据
  • 用值创建结构实例
  • 求问:带有重复元素全排列怎么按字典序输出啊
  • Permutation Recovery 代码不会写
  • Marbles in Three Baskets 程序怎么实现呢
  • Chessboard Dance 代码的设计问题
  • Party at Hali-Bula 是怎么写的呢
  • Barbara Bennett's Wild Numbers 程序的解决
  • Deciphering Password 密码的问题

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华