Home  >  Article  >  Web Front-end  >  Traverse the values ​​in the EL expression List collection in javascript

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

亚连
亚连Original
2018-05-17 10:55:233286browse

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}});  
}


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++)  
{  
  $(&#39;#qrcode&#39;+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 3f1c4e4b6b16bbbd69b2ee476dc4f83a2cacc6d41bbb37262a98f745aa00fbf0 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!

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