html模板中的Golang打印数组值
我不知道如何将数组中的值打印到html模板中 这是我的结构html模板中的Golang打印数组值,html,http,templates,go,Html,Http,Templates,Go,我不知道如何将数组中的值打印到html模板中 这是我的结构 type Lampen struct { Values [10]string } 我使用模板的代码如下 title := "moodlights" p := &lampen.Lampen{} err := p.LoadLampValues(title) if err != nil { log.Printf("Error loading Config File") for i := range p.Values
type Lampen struct {
Values [10]string
}
我使用模板的代码如下
title := "moodlights"
p := &lampen.Lampen{}
err := p.LoadLampValues(title)
if err != nil {
log.Printf("Error loading Config File")
for i := range p.Values {
p.Values[i] = "0"
}
}
t, _ := template.ParseFiles("template.html")
t.Execute(w, p)
"Values": [
"\u003e",
"",
"",
"",
"",
"",
"",
"",
"",
""
]
它所做的是从JSON文件加载值。
但是现在我不知道如何将这些值打印到html文件中。
工作原理如下:
<div>Lampe0: <input type="text" name="Lampe0" value={{index .Values 0}} maxlength="6"></div>
这相当于>,打印的html将
<div>Lampe0: <input type="text" name="Lampe0" value=> maxlength="6"></div>
所以它并没有逃脱
如何将其打印到html中以使其转义
更新2:
带有转义的旧工作版本可以在上看到,好吧,我似乎使用的是文本/模板,而不是html/模板。所以这基本上是我的错。感谢JimB指出这一点。您使用的是html/模板吗?是的,我正在使用html/模板。如前所述,问题在于,如果你现在输入了>