admin管理员组文章数量:1293769
I am trying to get familiar with javaScript and currently stumbled upon one issue: How to get ArrayList JSP variables in JavaScript function?
Fo example I figured out how I can get an int value, but dont know how to move the array list
var total='<%=counter%>'; //convert jsp to JavaScript
I am trying to get familiar with javaScript and currently stumbled upon one issue: How to get ArrayList JSP variables in JavaScript function?
Fo example I figured out how I can get an int value, but dont know how to move the array list
var total='<%=counter%>'; //convert jsp to JavaScript
Share
asked Jan 17, 2012 at 7:41
AndrewAndrew
7,79813 gold badges68 silver badges120 bronze badges
2 Answers
Reset to default 6There is no direct way to convert an ArrayList to javascript array, you can loop through the ArrayList and add each element to javascript array. try this
javascript:
var jsArray = [];
<%for(int i=0;i<arrayList.size();i++){%>
jsArray.push("<%= arrayList.get(i)%>");
<%}%>
You need to use javascript array and create the array using values from the server
var myArray=new Array("Value1","Value2","Value3");//condensed array
var myArray=["Value1","Value2","Value3"];//literal array
You can also use the JSON format to get the literal from the server.
本文标签: get ArrayList JSP variables in JavaScript functionStack Overflow
版权声明:本文标题:get ArrayList JSP variables in JavaScript function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741587807a2386947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论