Search code examples
grailsgsp

loop through 2 items using g:each in grails


Can I loop through more than 1 item in g:each tag in grails? I want to simultaneously loop through 2 items of same length and then display the response.

Any help on this is appreciated.


Solution

  • Yes, you can.
    You can use status to know which loop it is and which element to grab.

    <g:each in="${firstList}" status="i" var="elem">                
       <td>${secondList[i].attribute}</td> //you can access 2nd list elements like this
       <td>${elem.attribute}</td> //you can access first list elements like this
    </g:each>