0

I am trying to append a ArrayList to a JavaScript String variable using foreach loop but for some reason it doesn't seem to work. I have been trying to fix this problem for 2 days, but no luck yet. Can anyone help with this? Here's the code.

<div id="graphdiv"></div>

<script type="text/javascript">
    var s = "";
    <c:forEach items="${dateAndWaitTimes}" var="item">
        s.append(${item});
    </c:forEach>
    g = new Dygraph(document.getElementById("graphdiv"), s);
</script>

Here dateAndWaitTimes contains the ArrayList of String, returned by the controller.

-

Output that I am getting:

enter image description here

Expected Output:

enter image description here

Retr0spect
  • 187
  • 1
  • 13

1 Answers1

0

It seems you're getting array values correctly but nothing display correct. one solution might be : put Java arraylist values into JS arrayList and then print JS arrayList values.

Code :

<script language="javascript">
$(function(){
    var values = new Array();        
    <c:forEach var="item" items="${dateAndWaitTimes}" varStatus="status">
        values.push("${item}");   
    </c:forEach>
    alert(" VALUES => "+values[0]);
    alert(" VALUES => "+values[1]);
    //alert(" VALUES => "+values[2]);

});

Mohammadreza Khatami
  • 1,444
  • 2
  • 13
  • 27