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
Add a ment  | 

2 Answers 2

Reset to default 6

There 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