golang - go中如何把发送到模板的值遍历出来
本文介绍了golang - go中如何把发送到模板的值遍历出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
go中如何把发送到模板的值遍历出来
type TwoList struct {
Id int
Title string
}
type Two struct {
TwoList []TwoList
}
for rows.Next() {
rows.Scan(&id, &title)
Lists.TwoList = append(Lists.TwoList, &TwoList{Id: id, Title: title})
}
t, _:= template.ParseFiles("static/view/list.html")
t.Execute(w, Lists)
list.html
{{range .Lists}}
{{.Id}}
{{end}}
什么值都没有
解决方案
找到方法了
原来是要遍历TwoList就可以了
这篇关于golang - go中如何把发送到模板的值遍历出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文