Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to traverse Grails maps in jQuery
    text
    copied!<p>So, I obtain a set of results in my controller via SQL and pass it into the GSP, I then stick this data into a hidden field and looks like so: -</p> <pre><code>[ {forms_idx=0, form_id=21, events_idx=0, event_id=110, object_id=2, value=null}, {forms_idx=0, form_id=21, events_idx=1, event_id=109, object_id=3, value=null}, {forms_idx=1, form_id=22, events_idx=0, event_id=112, object_id=2, value=null}, {forms_idx=1, form_id=22, events_idx=1, event_id=111, object_id=1, value=null}, {forms_idx=2, form_id=23, events_idx=0, event_id=114, object_id=2, value=null}, {forms_idx=2, form_id=23, events_idx=1, event_id=113, object_id=3, value=null} ] </code></pre> <p>I then pass this through to a jQuery function via this: -</p> <pre><code>$(document).ready(function () { testing($("#myresults").val()); }); </code></pre> <p>I know this works because I've tried it with a simple static value and then put an alert into the testing function.</p> <p>My question is, how do I put a simple loop of some kind into my function now to address the results in the data I've passed it?! I've tried each etc but its not working and I'm probably missing something really basic, any suggestions? This is what I'm currently trying...</p> <pre><code>function testing(results){ $.each(results, function(index, value){ alert(index + " " + value) }) } </code></pre> <p>I also tried this but just got the value <code>undefined</code> back...</p> <pre><code>function testing(results){ alert(results); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload