解決問題:怎樣在頁面獲取數組和List集合的長度
我們在前端遍歷后台數據的時候,經常是從后台傳過來一個數組或List集合,在前端頁面就可以使用JSTL的<c:For each>標簽遍歷數據了。但是有時候我們需要更加深入控制遍歷的邏輯,這時候數組或List的長度就是一個必不可少的信息了。
首先,在jsp頁面上,我們不能夠使用${testList.length}和${testList.size}來獲取List集合的長度,這是EL表達式的API決定的。
那么,在jsp頁面上怎樣獲取數組或List集合的長度呢?
①導入JSTL的函數標簽庫
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
②使用fn:length函數
${fn:length(testList)}
——例 如:
<c:if test="${varStatus.count==fn:length(allInform)-1}"> <a class="blue" >下移<i class="ace-icon glyphicon glyphicon-arrow-down bigger-130"></i> </a> </c:if> <c:if test="${varStatus.count!=fn:length(allInform)-1}"> <a class="blue" href="#" onclick="javascript:location.href='${pageContext.request.contextPath}/manager/toInformDown/${inform.get(‘inform_order’)}'"> 下移<i class="ace-icon glyphicon glyphicon-arrow-down bigger-130"></i> </a> </c:if>
———————————————————————————————————————————————————————————————————
The end @ 萬有引力+
-
-
-
-
-