【发布时间】:2021-12-24 14:01:06
【问题描述】:
在这段代码中,我想在 HTML 文件中使用并给出一个特定的细节,比如标题或价格。
问题在于,有多个标题和价格,当我打印特定的标题和价格时,它会成功打印特定的数据,但我不知道如何在 HTML 文件中使用它来打印特定的数据。我所知道的关于 GOHTML 的只有 {{.Heading}},但它不起作用。有没有其他办法?
package main
import "net/http"
type Details struct {
Heading string
Price string
}
var Detail = []Details{
{
Heading: "First Cloth",
Price: "$59",
},
{
Heading: "Second Cloth",
Price: "$49",
},
}
func Main(w http.ResponseWriter, r *http.Request) {
HomeTmpl.Execute(w, Detail)
// fmt.Println(Detail[1].Heading) // For specific data
}
【问题讨论】:
标签: html go templates go-templates