为了账号安全,请及时绑定邮箱和手机立即绑定

revel框架中索引如何以1开头

revel框架中索引如何以1开头

Go
繁星点点滴滴 2023-07-31 14:59:38
  <tr>      <td>rank</td>      <td>abc</td>  </tr>  {{ range $index,$abc := .abc }}     <tr>      <td>{{$index}}</td> // 0      <td>{{$abc}}</td>     </tr>  {{end}}如何 {{$index}} 以 1 开头{{add $index 1}} - 函数“add”未定义{{$index + 1}} - 非法数字语法:“+”
查看完整描述

1 回答

?
慕的地6264312

TA贡献1817条经验 获得超6个赞

您可以将自定义函数作为变量传递到控制器的ViewArgs中。

controller.ViewArgs["addOne"] = func (i int64) {

    return i+1

}

然后您可以使用$.addOne循环访问该函数。要将其用作函数,您必须call在其前面添加关键字:


  <tr>

      <td>rank</td>

      <td>abc</td>

  </tr>

  {{ range $index, $abc := .abc }}

     <tr>

      <td>{{call $.addOne $index}}</td> // $index + 1

      <td>{{$abc}}</td>

     </tr>

  {{end}}


查看完整回答
反对 回复 2023-07-31
  • 1 回答
  • 0 关注
  • 60 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信