revel框架中index如何从1开始

How index starts with 1 in revel Framework

  <tr>
      <td>rank</td>
      <td>abc</td>
  </tr>
  {{ range $index,$abc := .abc }}
     <tr>
      <td>{{$index}}</td> // 0
      <td>{{$abc}}</td>
     </tr>
  {{end}}
  1. how to {{$index}} starts with 1

    {{add $index 1}} - unction "add" not defined

    {{$index + 1}} - illegal number syntax: "+"

您可以将自定义函数作为变量传递给控制器​​的 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}}