dongzhi9032 2015-02-20 17:40
浏览 25
已采纳

转到模板循环(排列)出注释

At the end of my posts.html I need to loop over 2 elements in the Struct as without range I just get the last entry in mysql but although the rest of the structure stuff above is rendering fine the html output stops when it hits the range. Do i need to specify to only range over 2 elements in my Struct ?

{{range .}}
<p>{{.Name}}</p>
<p>{{.Comment}}</p>
{{end}}

Here is my current go code - http://play.golang.org/p/QMT12qfaoC

As an aside I have also lost the ability to render only mysql data matching the URL which also needs fixing.

  • 写回答

1条回答 默认 最新

  • dongwo5449 2015-02-20 18:36
    关注

    Do i need to specify to only range over 2 elements in my Struct ?

    You don't need to range over fields in a struct, this would be enough since you are just passing one post to post.html :

    <p>{{.Name}}</p>
    <p>{{.Comment}}</p>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 这个公式写进SIMULINK中的function模块的代码中应该是什么样的
  • ¥15 javaweb登陆的网页为什么不能正确连接查询数据库
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信