简体   繁体   English

将jstl的foreach varStatus传递给javascript

[英]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. 但是,使用名称“ count for varStatus会造成混淆”。“ count”是LoopTagStatus接口中当前基于1的迭代计数的名称。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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