我是 golang 新手。我想将多个变量传递给html。所以我有这样的类型:
type Variables struct {
UserNames []string
Checks []string
}
Run Code Online (Sandbox Code Playgroud)
传递了正确值的页面变量
var PageVars Variables
PageVars = Variables{
UserNames: ulist,
Checks: check,
}
log.Println("ulist",ulist)
err = tpl.Execute(w, PageVars) //execute the template and pass it to index page
if err != nil { // if there is an error
log.Print("template executing error: ", err) //log it on terminal
}
Run Code Online (Sandbox Code Playgroud)
我想将用户名和检查传递给 html 模板,例如:
{{range .UserNames .Checks}}
{{.UserNames}}: <input type="checkbox" name="email" value={{. UserNames}} {{.Checks}}/><br />
{{end}}
Run Code Online (Sandbox Code Playgroud)
但没有成功。谁能纠正我的语法吗?多谢。