简体   繁体   中英

Passing jstl's foreach varStatus into javascript

is this possible?

<c:forEach var="list" items="${requestScope.data}" varStatus="count">

<script>
myFunction(false,[]) // this is where i want to pass the `varStatus` on 2nd argument 
</script>

</c:forEach>

i've tried putting like :

myFunction(false,${count.index});
myFunction(false,<c:out value="${count.index}"></c:out>);

none of those worked. Any help would be appreciated. Thanks!

Please try these tests. They all work for me. But, using the name "count for varStatus is confusing. "count" is the name of the current 1-based iteration count in the LoopTagStatus interface.

<c:forEach var="list" items="a,b,c" varStatus="count">
    myFunction(false,${count.index}) <br/>
</c:forEach>

<c:forEach var="list" items="a,b,c" varStatus="status">
   myFunction(false,${status.index}) <br/>
</c:forEach>

<c:forEach var="list" items="a,b,c" varStatus="status">
    my Function(false,${status.count}) <br/>
</c:forEach>

<c:forEach var="list" items="a,b,c" varStatus="count">
    my Function(false,${count.count}) <br/>
</c:forEach>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM