可以使用gin-gonic将html页面中的值数组绑定到数组中。
<form method="POST" action="mygo">
<input type=hidden name="emails" value="email1@email.com">
<input type=hidden name="emails" value="email2@email.com">
<input type=hidden name="emails" value="email3@email.com">
</form>
可以使用
进行解析func Handler( c *gin.Context) {
emails:= c.PostFormArray("emails")
}
这是从html页面绑定对象数组的方法吗? 像这样
<form method="POST" action="mygo">
<input name="users[0].name" value="John"> <input name="users[0].email" value="john@email.com">
<input name="users[1].name" value="Jack"> <input name="users[1].email" value="jack@email.com">
</form>
绑定这样的东西
type User struct {
Name string
Email string
}
type Users struct {
Users []User
}
func Handler( c *gin.Context) {
users:=Users{}
c.Bind(&users)
log.Println(users.Users[0]) // John john@email.com
}