drsdvwsvo78320812 2014-05-17 16:47
浏览 507

如何在Golang Beego中解析表单数组

How to parse html form array with Beego.

<input name="names[]" type="text" /> <input name="names[]" type="text" /> <input name="names[]" type="text" />

Go Beego

type Rsvp struct {
    Id    int      `form:"-"`
    Names []string `form:"names[]"`
}

rsvp := Rsvp{}
if err := this.ParseForm(&rsvp); err != nil {
    //handle error
}

input := this.Input()
fmt.Printf("%+v
", input) // map[names[]:[name1 name2 name3]]
fmt.Printf("%+v
", rsvp) // {Names:[]}

Why Beego ParseForm method return an empty names?

How to get values into rsvp.Names?

  • 写回答

3条回答 默认 最新

  • dsfsd43523 2014-05-27 04:06
    关注

    As you can see from the implementation of the FormValue method of the Request, it returns the first value in case of multiple ones: http://golang.org/src/pkg/net/http/request.go?s=23078:23124#L795 It would be better to get the attribute itself r.Form[key] and iterate over all the results manually. I am not sure how Beego works, but just using the raw Request.ParseForm and Request.Form or Request.PostForm maps should do the job. http://golang.org/src/pkg/net/http/request.go?s=1939:6442#L61

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效