【发布时间】:2020-12-03 09:04:58
【问题描述】:
我尝试使用此模板行从“2020-03-09T08:09:40.000+0000”获取日期(2020-03-09):
... [Ticket:{{- .key -}}:{{ .fields.resolution.name }}] starts {{ slice .fields.created 0 10 }} and ends {{ slice .fields.resolutiondate 0 10 }} ...
--> 无效用法:模板:gojira:7:62:在
文档说:
切片
slice 返回将其第一个参数切片的结果 剩下的论据。因此,“切片 x 1 2”在 Go 语法中是 x[1:2], 而“切片 x”是 x[:],“切片 x 1”是 x[1:],“切片 x 1 2 3” 是 x[1:2:3]。第一个参数必须是字符串、切片或数组。
这里是我在 go-jira 中使用的完整模板:
@startgantt
{{ range .issues -}}
[Ticket:{{- .key -}}:{{ .fields.resolution.name }}] starts {{ slice .fields.created 0 10 }} and ends {{ slice .fields.resolutiondate 0 10 }}
[Ticket:{{- .key -}}:{{ .fields.resolution.name }}] is colored Yellow
{{ if (and .fields.customfield_11202 .fields.customfield_11203) -}}
[Planned:{{- .key -}}:{{ .fields.resolution.name }}] starts {{ .fields.customfield_11202 }} and ends {{ .fields.customfield_11203 }}
[Planned:{{- .key -}}:{{ .fields.resolution.name }}] is colored LightBlue
{{ end -}}
{{ end -}}
@endgantt
【问题讨论】:
-
你使用的是什么版本的 go?切片字符串工作得很好:play.golang.org/p/SnHsZPqiao5
-
> go-jira 1.0.23 >go version >go version go1.10.4 linux/amd64 >lsb_release -a >没有可用的 LSB 模块。 >发行商 ID:Ubuntu >描述:Ubuntu 18.04.5 LTS >发行版:18.04 >代号:仿生 >wsl 1 (Windows for Linux) 版本 10.0.17134.885
标签: string go templates jira slice