问题
I have the following code:
<g:select name="availableUser.id" from="${availableUsers}"
noSelection="['': message(code: 'global.noSelection')]"
optionKey="id" value="${name}"
onchange="${remoteFunction(
controller: 'report',
action: 'getAvailableUsers',
params: [report: reportInstance.id, user: this.value],
update: 'userSelection'
)}">
In remote function getAvailableUser I can access passed parameter named report but the other one(user) is constantly returning null even though combobox is properly rendered. Like this:
...
<option value="21">John Smith</option>
...
I'm trying to get the value of selected item. In this instance, 21.
回答1:
This is because remoteFunction
in turn writes a JS function which fires an AJAX request based on the corressponding library used (JQuery
, DOJO
etc). params
attribute is requried to me mentioned in the native format based on the AJAX library you use for your project.
Mark the difference when different libraries are used
JQuery:
'\'user.id=\' + this.value + \'&report=\' + ${reportInstance.id}'
DOJO: [Use of Semi colons for Key-value pair]
'\'user.id:\' + this.value + \', report:\' + ${reportInstance.id}'
来源:https://stackoverflow.com/questions/16194621/passing-two-parameters-from-combobox-onchange-event