【发布时间】:2020-06-29 17:37:06
【问题描述】:
有两种结构:
Offers := "10% Discunt"
SelectUsers := "ALL"
OpenDate := "29-06-2020"
closedDate := "29-07-2020"
}
type ScanInfo struct{
IdScan := "1212"
Longitude := "98.323202"
Latitude:= "34.432201"
}
Go方法:
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
tmpl := template.Must(template.ParseFiles("home.html"))
var scans []ScanInfo
var infos []info
tmpl.Execute(w, struct{ ScanData []ScanInfo }{scans})
})
我在html表中获取单一类型数据的方法是:
<tbody>
{{ range .ScanData }}
<tr>
<th>{{.IdScan}}</th>
<th>{{.Longitude}}</th>
<th>{{.Latitude}}</th>
</tr>
{{ end }}
</tbody>
现在我想一次将结构的 (info & ScanInfo's) 数据发送到 HTML 表单 (home.html) 中。 无论如何,请建议我发送此数据,以及如何将这些值输入 HTML 页面。
【问题讨论】:
-
这能回答你的问题吗? golang template with multiple structs
-
没有。这用于单个结构。但我需要一次发送多个结构。