Home > Web Front-end > JS Tutorial > body text

Traverse the values ​​in the EL expression List collection in javascript

亚连
Release: 2018-05-17 10:55:23
Original
3182 people have browsed it

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++)  
{  
  $(&#39;#qrcode&#39;+i).qrcode({text: ${myTickets[i].url}});  
}
Copy after login


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})  
}
Copy after login


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++)  
{  
  $(&#39;#qrcode&#39;+i).qrcode({text: ctx+"/wxpay/"+array[i]});  
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!