Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery $.each() JSON array object iteration
    text
    copied!<p>I am having some real difficulty attempting to solve a JQuery $.each() iteration</p> <p>This is my array, limiting results for convenience</p> <pre><code>[{"GROUP_ID":"143", "GROUP_TYPE":"2011 Season", "EVENTS":[ {"EVENT_ID":"374","SHORT_DESC":"Wake Forest"}, {"EVENT_ID":"376","SHORT_DESC":"Yale"}, {"EVENT_ID":"377","SHORT_DESC":"Michigan State"}] }, {"GROUP_ID":"142", "GROUP_TYPE":"2010 Season", "EVENTS":[ {"EVENT_ID":"370","SHORT_DESC":"Duke"}, {"EVENT_ID":"371","SHORT_DESC":"Northwestern"}, {"EVENT_ID":"372","SHORT_DESC":"Brown"}] }] </code></pre> <p>My first $.each iteration works very well, but the sub iteration for "EVENTS" is where I am having issues</p> <p>My first $.each() function</p> <pre><code> $.each(json, function(key) { html = '&lt;a href="'+json[key].GROUP_ID+'"&gt;'; .... </code></pre> <p>My non-working second $.each() function</p> <pre><code> $.each(json.EVENTS, function(key) { newHTML += '&lt;p&gt;'+json.EVENTS[key].SHORT_DESC+'&lt;/p&gt;'; ... </code></pre> <p>I am understanding (loosely) that this is not a singular JSON object, but a JSON array of objects, but not understanding if the first version works why the second does not</p> <p>the end result I want to achieve once I understand this is an $.each() within an $.each(), I know the code below does not work, and more than likely idiotic, but gives an idea of what im trying to achieve : iterate through parent then child by parent</p> <pre><code>$.each(json, function(key) { html = '&lt;a href="'+json[key].GROUP_ID+'"&gt;'; $.each(json[key].EVENTS, function(subkey) { html = '&lt;a href="'+json[key]EVENTS[subkey].SHORT_DESC+'"&gt;'; ... </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