问题
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