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

Golang如何从html / template访问切片字段

I have a []struct{} and that []struct{} has a field called ThreadName and I'm trying to access that from in the template like so:

{{ index .Posts 0 $.ThreadName}}

not sure how to do this properly any information would be great thanks.

Use the following to access the thread name of the first post:

{{(index .Posts 0).ThreadName}}

playground example

近期文章

  • 进行错误处理,使事情变干的惯用方式是什么
  • Go中的大int范围
  • 在Go中转换切片的一部分?
  • 如何在golang的不同文件中访问同一包中未导出的函数?
  • 引用子结构数组的Golang问题
  • 如何检测gorm中的连接失败?
  • CookieJar在哪里保留cookie?
  • int16数字加上golang中的float64
  • 如何在golang中比较funcs
  • 可以包含任何类型的数据结构是什么?
  • 在REST上不受支持的HTTP方法上返回什么响应代码?
  • 正则表达式匹配对我来说很奇怪
  • 在Go中自定义测试
  • 结构类型不可变
  • 在Go程序中使用多个文件
  • 如何使用Go将对象数组插入MongoDB
  • 使用RPM将字节转为整数编码
  • 图像未显示在Golang上带有img的html上的文字
  • 如何在OS X,CentOS 6上构建goncurses
  • http.client的图“无效的内存地址……”来源

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华