A problem I encountered today is that I want to get the value in the list sent from the background in js. Originally, the page was displayed using ELexpression, and everything was fine. However, I needed to dynamically obtain the URL in the collection and then call qrcode in js to generate the QR code. When I tried to follow most of the ideas When getting the value, I encountered the following problem
for(var i=0;i<${myTickets.size()};i++) { $('#qrcode'+i).qrcode({text: ${myTickets[i].url}}); }
Hahaha, I used the debugging tool to see that ${myTickets.size()} did get the length of the list, but $ {myTickets[i].url}} cannot get any value!
Then I tried to get the value as follows
[javascript] view plain copy for(var i=0;i<${myTickets.size()};i++) { alert(${myTickets[0].url}) }
Hahaha, it hurts when I take it out. But the problem lies here: when using EL expression ${myTickets[i].url} in for loop, i cannot get the value, which means that EL expression cannot use JS The variable in the EL expression is a whole. Specifically, we can do the following, use foreach in JS to take out the push value into the array, and then loop to traverse the array, which can be a perfect solution:
[javascript] view plain copy var array = new Array(); <c:forEach items="${myTickets}" var="t"> array.push(${t.ticketNo}); //js中可以使用此标签,将EL表达式中的值push到数组中 </c:forEach> for(var i=0;i<array.length;i++) { $('#qrcode'+i).qrcode({text: ctx+"/wxpay/"+array[i]}); }
above I compiled it for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to use el expressions in <script></script> tags
##Focus on analysis and answers to js and el expression operation list
Detailed introduction to the use of EL expressions in JS
The above is the detailed content of Traverse the values in the EL expression List collection in javascript. For more information, please follow other related articles on the PHP Chinese website!