我尝试在 text/html 模板包中获得一些优点。我已经从 golang 站点阅读了它的文档。很难理解 . (点)在一般情况下,在一定的时间范围内动作。“管道”究竟是什么意思,可能因为我的英语不是母语而难以理解):{{pipeline}}The default textual representation of the value of the pipelineis copied to the output.让我们考虑一个例子: data := map[string]interface{}{ "struct": &Order{ ID: 1, CustID: 2, Total: 3.65, Name: "Something", }, "name1": "Timur", "name2": "Renat", } t.ExecuteTemplate(rw, "index", data)这是“索引”:{{define "index"}} {{range $x := .}} {{.}} <b>{{$x}}</b><br> <i>{{$.struct.ID}}</i><br> <br> # the lines below don't work and break the loop # {{.ID}} # or # {{.struct.ID}} # what if I want here another range loop that handles "struct" members # when I reach "struct" field in the data variable or just do nothing # and just continue the loop? {{end}}{{end}}输出:帖木儿帖木儿1长Renat长Renat1{1 2 3.65 某事}{1 2 3.65 某事}1
1 回答
- 1 回答
- 0 关注
- 164 浏览
添加回答
举报
0/150
提交
取消