我嘗試在 text/html 模板包中獲得一些優(yōu)點。我已經(jīng)從 golang 站點閱讀了它的文檔。很難理解 . (點)在一般情況下,在一定的時間范圍內(nèi)動作?!肮艿馈本烤故鞘裁匆馑?,可能因為我的英語不是母語而難以理解):{{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 回答
- 0 關(guān)注
- 179 瀏覽
添加回答
舉報
0/150
提交
取消