Grails Indexed Properties with No Real Index

时光怂恿深爱的人放手 提交于 2020-01-17 08:02:32

问题


Grails 1.3.1

I am using a jQuery library that sends a serialized parameter map to the server and it is formatted like so....

item[]=1&item[]=2&item[]=3

In my controller, when I do println params, it comes out...

[item[]: [1, 2, 3]]

I can't seem to get this data out of params in my controller, however. What am I missing?


回答1:


An HTTP Post sends name/value pairs up to the web server. These names are based on the names within the given HTML form controls.

When duplicates exist, they're combined into a comma delimited list of values.

So, "item=1&item=2&item=3" becomes "item=1,2,3" on the server side. You can create an array from the comma delimited string and use the values. This is how you'll process selected items from a tag that allows multiple items to be selected.

If you want to keep the values separate, they'll have to use different names on your HTML form tags.




回答2:


This worked...

params['items[]']



来源:https://stackoverflow.com/questions/3142392/grails-indexed-properties-with-no-real-index

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!