Search code examples
loopsgrailseachgsp

Grails - First Ten Values only in g:each


<g:each in="${checking}" status="i" var="checking2">
<g:if test="${i<10}" >//Break The Loop</g:if>
//Do My Work Here
</g:each>

In above example, if its possible to get only first ten values from 'checking'. Suppose checking returns 100 values, I would like to access only first ten values.

I know that is possible by using max:10 in controller and returning only 10 values in list, but I want as stated above.

PS: I am new to this....


Solution

  • Try some thing like this

    <g:each in="[0..9]" var="index">
      <g:set var="item" value="${checking[index]}" />
      //do whatever you want with item
    </g:each>
    

    In short, iterate over range 0..9 and use index as index to your list.