1 回答

TA贡献1807条经验 获得超9个赞
绑定所以不起作用。表单的字段 - name = "fields [1]" 和 name = "fields [0]" 彼此独立,因此对于它们中的每一个,您的结构都应包含自己的字段:
type FormInfo struct {
Fields1 string
Fields2 string
Action string
PageTitle string
Id string
}
分别在处理程序中:
...
&f.Fields1: "fields[0]",
&f.Fields2: "fields[1]",
&f.Action: "action",
...
结果,输出将是:
(*main.FormInfo)(0xc08200aa50)({
Fields1: (string) (len=7) "value 1",
Fields2: (string) (len=7) "value 2",
Action: (string) (len=4) "save",
PageTitle: (string) "",
Id: (string) ""
})
编辑:
如果您更改表单上的代码
...
<input type="text" name="fields"...
<input type="text" name="fields"...
你可以得到
info.Fields = [value 1 value 2]
无需更改其原始代码。
- 1 回答
- 0 关注
- 220 浏览
添加回答
举报