在 JSP 中设置变量并在 jquery 中使用它
setting a variable in JSP and using it in jquery
我有一个路线对象。它包含选项数组列表。我想知道选项的大小并将其存储在某个变量中。 (这件事需要在JSP完成)。然后我想在 jquery 中访问这个变量。怎么做?
JSP代码:
<%!int loopSize = routes.get(0).getOptions().size(); %>
<c:forEach var="route" items="${routes}" varStatus="loopCounter">
<c:forEach var="option" items="${route.options}"
varStatus="loopCounter2">
<---more code -->
</c:forEach>
</c:forEach>
但是它说路由未定义。我正在使用 struts2 和操作 class。路线来自行动 class
一种解决方案可能是将数组的长度存储在隐藏字段中并在 jquery 中访问它。
<input type="hidden" id="loopSize" name= "loopSize" value= "${fn:length(routes[0].options)}"/>
并且使用 id 您可以访问 jquery
中的值
我有一个路线对象。它包含选项数组列表。我想知道选项的大小并将其存储在某个变量中。 (这件事需要在JSP完成)。然后我想在 jquery 中访问这个变量。怎么做?
JSP代码:
<%!int loopSize = routes.get(0).getOptions().size(); %>
<c:forEach var="route" items="${routes}" varStatus="loopCounter">
<c:forEach var="option" items="${route.options}"
varStatus="loopCounter2">
<---more code -->
</c:forEach>
</c:forEach>
但是它说路由未定义。我正在使用 struts2 和操作 class。路线来自行动 class
一种解决方案可能是将数组的长度存储在隐藏字段中并在 jquery 中访问它。
<input type="hidden" id="loopSize" name= "loopSize" value= "${fn:length(routes[0].options)}"/>
并且使用 id 您可以访问 jquery
中的值