I'm trying to add new field to existing gsp page which was written by some other guy.
<g:select name="clientId" multiple = "yes" size = "4" from="${com.mycompany.fleet.partymodel.roles.ClientRole.list()}" class = "filter_combo" optionKey="id" />
and by using jQuery he is getting selected values like this
var selectedclients = "${clientId}";
console.log(selectedclients); // prin开发者_如何学Cts id of selected Clients
I'm adding new drop down like this in same page
<g:select name="contractId" multiple = "yes" size = "4" from="${com.mycompany.fleet.rules.Contract.list()}" class = "filter_combo" optionKey="id"/>
and I'm trying to get the selected values using jQuery like this
var selectedcontracts = "${contractId}";
but its not fetching the selected values... am I doing anything wrong here?
What does the ${clientId}
mean exactly?
I don't believe that is using JQuery, that is just putting the current value for clientId
into the javascript for var selectedclients = "${clientId}";
using standard GSP templating.
ie: when the page is generated, ${clientId}
gets replaced with the value in the model
Are you adding contractId
to the model in the Controller?
One thing to watch out for here is that if the clientId
or contractId
has a double quote in them (ie, if clientId was Tim"busy" Yates
, then this will generate invalid javascript, as the generated code would look like:
var selectedclients = "Tim "working" Yates" ;
However, if it's just an integer id then I guess this would be ok
How about:
var selectedcontracts = $('select [name="contractId"]').val();
精彩评论