2017-04-11 60 views

回答

2

如果check the errorExecute回来,你会发现,模板试图将参数传递给非功能$我。正确的语法是:

const t = `{{range $i, $v := .}}{{$i}} {{$v}}{{if gt $i 0}}, {{end}} 
{{end}} 
` 

参数遵循功能gt。功能gt不是infix operator

playground example

如果你的目标是要打印一个逗号分隔的列表,然后把它写这样的:

const t = `{{range $i, $v := .}}{{if $i}}, 
{{end}}{{$i}} {{$v}}{{end}} 
` 

playground example

+0

感谢。当我浏览文档时,我错过了整个前缀部分:) – shyam