Bri*_*ica 8 variadic-functions go go-templates
有没有办法在 Go 模板中“传播”参数?
在我的代码中,我有一个函数将结构列表的属性作为字符串切片返回
"colStr": func(col string, a ...interface{}) []string {
s := make([]string, len(a))
for i, v := range a {
if structs.IsStruct(v) {
s[i] = db.Str(structs.Map(v)[col])
}
}
return s
},
Run Code Online (Sandbox Code Playgroud)
但我如何传递给这个函数呢?在模板本身中,我有一些看起来像这样的东西
{{list (colStr `Number` .QuoteProofs...) `&`}}{{end}}
Run Code Online (Sandbox Code Playgroud)
但这给了我
模板:HTML:17:操作数中出现意外的 <.>
有没有办法用模板来做到这一点?