gpt4 book ai didi

jsp - 如何获取 foreach jSTL 标签中的项目数?

转载 作者:行者123 更新时间:2023-12-01 09:57:46 24 4
gpt4 key购买 nike

我在 javascript <script></script> 下有以下代码:

<c:forEach items="${lifeEvents}" var="event" varStatus="loop">
latitudes["${loop.index}"] = <c:out value="${event.place.location.latitude}"/>;
longitudes["${loop.index}"] = <c:out value="${event.place.location.longitude}"/>;
lastEvent = "${loop.index}";
if("${loop.index}" > 0)
waypointEvents["${loop.index}"] = new google.maps.LatLng(latitudes["${loop.index}"],longitudes["${loop.index}"]);
</c:forEach>

我如何知道 lifeEvents 列表中存在的 LifeEvents 的确切数量?在运行整个循环直到结束之前

最佳答案

如果你的 lifeEvents 是一个集合,那么你可以使用 jSTL 获取集合的大小fn:长度

<c:out value="${fn:length(lifeEvents)}" /> <%-- size of liveEvents --%>

确保在页面顶部添加了以下 taglib 以允许 fn 命名空间。
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

关于jsp - 如何获取 foreach jSTL 标签中的项目数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22038396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com