相关疑难解决方法(0)

使用范围从模板构建时,Go无法评估字段

我在Go程序中有Files一些File结构来保存文件的名称和大小.我创建了模板,见下文:

type File struct {
    FileName string
    FileSize int64
}
var Files []File
const tmpl = `
    {{range .Files}}
    file {{.}}
    {{end}}
    `
t := template.Must(template.New("html").Parse(tmplhtml))
    err = t.Execute(os.Stdout, Files)
    if err != nil { panic(err) }
Run Code Online (Sandbox Code Playgroud)

我当然害怕说:

无法评估[] main.File类型中的字段文件

不确定如何range在模板中正确显示文件名和大小.

go go-templates

1
推荐指数
1
解决办法
3195
查看次数

标签 统计

go ×1

go-templates ×1