迭代集合并将结果放入变量?

时间:2012-02-21 18:37:52

标签: jstl

我试过问这个问题,但可能措辞错了。我这样做:

<c:forEach var="cell" items="${row}" varStatus="rowStatus">
    <td class="data_extract">
        <c:choose>
            <c:when test="${results.types[rowStatus.index].array}">
                <c:forEach var="elem" items="${cell}" varStatus="cellStatus">
                    ${elem}<c:if test="${!cellStatus.last}">,&nbsp;</c:if>
                </c:forEach>
            </c:when>
            <c:otherwise>
                ${cell}
            </c:otherwise>
        </c:choose>
    </td>

例如${elem}将循环几次并将在单元格中显示:“10GT,137S”循环完成后。我想要为变量连接,所以“10GT,137S”被赋予一个变量,以便我可以传入:

<span class="mouseover_text" title="${NEW VARIABLE HERE!!!!!!!}"></span>

请帮助兄弟......

编辑: 这似乎有用!!

<td class="data_extract">
    <c:choose>
        <c:when test="${results.types[rowStatus.index].array}">
            <c:set var="comma" value="," />
            <c:forEach var="elem" items="${cell}" varStatus="cellStatus">
                <c:set var="myVar" value="${cellStatus.first ? '' : myVar} ${elem} ${cellStatus.last ? '' : comma}" /> 
            </c:forEach>
            <span class="mouseover_text" title="${myVar}">${myVar}</span>
        </c:when>
        <c:otherwise>
            ${cell}
        </c:otherwise>
    </c:choose>
</td>

1 个答案:

答案 0 :(得分:0)

<td class="data_extract">
    <c:choose>
        <c:when test="${results.types[rowStatus.index].array}">
            <c:set var="comma" value="," />
            <c:forEach var="elem" items="${cell}" varStatus="cellStatus">
                <c:set var="myVar" value="${cellStatus.first ? '' : myVar} ${elem} ${cellStatus.last ? '' : comma}" /> 
            </c:forEach>
            <span class="mouseover_text" title="${myVar}">${myVar}</span>
        </c:when>
        <c:otherwise>
            ${cell}
        </c:otherwise>
    </c:choose>
</td>