迭代集合并将结果放入变量中?
我尝试问这个问题,但可能措辞错误。我正在这样做:
<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>
例如 ${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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)