each
目的 Purpose
Uses the Groovy JDK each method to iterate over each element of the specified object.使用例 Examples
<g:each in="${books}"> <p>Title: ${it.title}</p> <p>Author: ${it.author}</p> </g:each>
<g:each var="book" in="${books}"> <p>Title: ${book.title}</p> <p>Author: ${book.author}</p> </g:each>
<ul> <g:each var="i" in="${ (0..<100) }"> <li>Item ${i}</li> </g:each> </ul>
<g:each in="${itemList}" var="item"> <g:link action="show" id="${item.id}">${item.title}</g:link> </g:each>
<tbody> <g:each status="i" in="${itemList}" var="item"> <!-- Alternate CSS classes for the rows. --> <tr class="${ (i % 2) == 0 ? 'a' : 'b'}"> <td>${item.id?.encodeAsHTML()}</td> <td>${item.parentId?.encodeAsHTML()}</td> <td>${item.type?.encodeAsHTML()}</td> <td>${item.status?.encodeAsHTML()}</td> </tr> </g:each> </tbody>
詳細 Description
属性 Attributes
in
- The object to iterate overstatus
(optional) - The name of a variable to store the iteration index in. Starts with 0 and increments for each iteration. If this parameter is used, thenvar
is required.var
(optional) - The name of the item, defaults to "it".
Note thatvar
attribute must be specified when the iterator value is to be used from within the body of a GSP Dynamic Tag, such as in<g:link>
.