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

模板中的for循环

I need for loop in template.

for i := start; i < finish; i++ {
    // do something
}

Is it just one way by using range with prepared array or how can I add this functional to templates?

The simplest way is probably to use range and an external function. For example (On play):

func For(start, end int) <-chan int {
    c := make(chan int)
    go func() {
        for i := start; i < end; i++ {
            c <- i
        }
        close(c)
    }()
    return c
}

in the template:

{{range For 0 10}}
i: {{.}}
{{end}}

近期文章

  • 了解Go中的fmt软件包
  • 在go中获取已卸载卷的BLKID
  • GAE数据存储区,带有投影的GetMulti()?
  • Go模板:遍历索引
  • Golang / mgo-设置“ $ set”为更新条件
  • 多个响应。Go中的WriteHeader调用
  • 如何通过Gmail API发送电子邮件? 走
  • 转到:内置的功能-容量是否有所不同
  • 您如何使用go-simplejson遍历json文件
  • 通过反射嵌套参考结构
  • 使用空字段创建结构的一线工具?
  • Go使用哪个IDE? [关闭]
  • 在Windows中编译Go文件?
  • 在golang示例中运行测试时“不允许导入周期”
  • 如何在Golang中使用javascript获取特定的网站元素或提交表单
  • Golang频道维护
  • 如何验证JWT签名?
  • 为什么binary.Size()返回(-1)?
  • 将字符串类型转换为int
  • Go探查器的输出令人困惑(且不正确?)

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华