假设目前在gsp中:
<g:each in="${prospectProjectStatuses}" var="statusObj">
<%-- Number active and inactive projects --%>
<g:if test="${statusObj?.project?.active == true}">
<g:set var="numActiveProjects" value="${numActiveProjects + 1}"/>
</g:if>
<g:else>
<g:set var="numInactiveProjects" value="${numInactiveProjects + 1}"/>
</g:else>
<%-- Number of hidden rows to show --%>
<g:if test="${!statusObj?.project?.id.intValue() && !canEdit && statusObj?.status?.id}">
<g:set var="numProjectsToShow" value="${numProjectsToShow + 1}"/>
</g:if>
<g:if test="${statusObj?.project?.active && statusObj?.status?.id}">
<g:set var="numStatusSet" value="${numStatusSet + 1}"/>
</g:if>
</g:each>
控制器方法中每个循环的等价物是什么?
答案 0 :(得分:3)
调用集合中的each()。所以gsp的示例等价如下:
prospectProjectStatuses.each { statusObj ->
if (statusObj?.project?.active) {
numActiveProjects += 1
} else {
numInactiveProjects += 1
}
if (statusObj?.project?.id.intValue() && !canEdit && statusObj?.status?.id) {
numProjectsToShow += 1
}
if {statusObj?.project?.active && statusObj?.status?.id) {
numStatusSet += 1
}
}