在JS中如何遍历一个EL表达式的集合

JavaScript034

在JS中如何遍历一个EL表达式的集合,第1张

两种情况

1. JS代码在JSP页面中, 这可以直接使用EL表达式. 如:

[html] view plain copy print?

<script type="text/javascript">

$(function () {

new BacklogOverview("${param.alert}")

})

</script>

2.JS代码是单独的.js 文件, 通过引入到 JSP中来.这时候可通过提前定义JS变量的形式的解决,如:

[html] view plain copy print?

<c:set var="contextPath" value="${pageContext.request.contextPath}" scope="application"/>

<script>

<%--JS gloable varilible--%>

var contextPath = "${contextPath}"

</script>

在JSP页面上定义JS变量 contextPath.

这样在之后引入的JS文件中就可以使用contextPath变量了.

[html] view plain copy print?

//Image setting

config.filebrowserImageUploadUrl = contextPath + "/ckeditor/upload.htm"

第一种:普通for循环

for(j = 0 j < arr.length j++) {

   

}

第二种:优化版for循环

for(j = 0,len=arr.length j < len j++) {

   

}

第三种:弱化版for循环

for(j = 0 arr[j]!=null j++) {

   

}

第四种:foreach循环

arr.forEach(function(e){  

   

})

第五种:foreach变种

Array.prototype.forEach.call(arr,function(el){  

   

})

第六种:for in循环

for(j in arr) {

   

}

第七种:map遍历

arr.map(function(n){  

   

})

第八种:forof遍历(需要ES6支持)

for(let value of arr) {  

   

})

看你的list的数据结构,就相当于是一个存放了n个map的list,你这里的业务需求就是要遍历出来所有的map。那你就要在后台把这个list传到页面去,setAttribute("positions",positions)

那你就在页面用forEach标签展示就可以了。

<c:forEach items="${positions}" var="car">

纬度:${car.latitude}<span/>

经度:${car.longitude}<span/>

<c:forEach/>

至于这个forEach放在什么地方,就按照你们业务的需求来了!

麻雀虽小,但也是肉啊!我收了!