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

发布于 2025-01-07 13:42:53 字数 1531 浏览 1 评论 0原文

我尝试问这个问题,但可能措辞错误。我正在这样做:

<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”就被分配了一个变量,这样我就可以传递到:

请帮助兄弟...

编辑: 这似乎有效!

<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>

I tried asking this question but may have worded it wrong. Im doing this:

<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}">, </c:if>
                </c:forEach>
            </c:when>
            <c:otherwise>
                ${cell}
            </c:otherwise>
        </c:choose>
    </td>

For example ${elem} will loop a couple times and will have this in the cell: "10GT, 137S" after the loop is done. I want to maybe concatenante a variable so "10GT, 137S" is assigned a variable so that I might pass into:

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

Please help a brother...

EDIT:
This seems to work!!

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱咩 2025-01-14 13:42:53
<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>
<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文