如何将Java数组列表转换为JavaScript数组? [英] How to convert java arraylist to javascript array?

查看:472
本文介绍了如何将Java数组列表转换为JavaScript数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何转换成字符串的Java数组对象列表以Java脚本阵列?

How do we convert java array list of String objects to java script array?

这是我在做什么,但是我正在寻找一个更好的方式来做到这一点。我不想遍历数组列表。

This is what I am doing but I am looking for a better way to do it. I dont want to iterate over the array list.

var myArray = [
<c:forEach items="${myList}" var="item">
            {itemName: "${item.name}"},
</c:forEach>
        ];

感谢。

推荐答案

有,是将Java的ArrayList转换为JavaScript数组没有直接的方法。结果
你必须完成下面的操作结果之一
1.转换了Java的ArrayList的JSON字符串,然后通过解析字符串转换为JavaScript数组。结果
2.直接写的ArrayList(使用小脚本)的Javascript字符串,然后分割/分析它的数组。结果
3.通过调用ArrayList.toString()作为响应发送一个字符串,然后按照步骤2。

There is no direct way to convert the Java ArrayList to the Javascript Array.
You have to do one of the following step
1. Convert the Java ArrayList to the JSON String and then convert it to Javascript Array by parsing the String.
2. Directly write the ArrayList (using scriptlet) to the Javascript String and then split/parse it the the array.
3. Send a string by calling ArrayList.toString() as a response and then follow the Step 2.

这篇关于如何将Java数组列表转换为JavaScript数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆