简体   繁体   English

在Javascript函数中获取Java对象属性

[英]Get Java Object properties in Javascript function

I am getting an arraylist of objects from Java class and I want to pass this arraylist to a javascript function and get each object's properties inside the javascript function. 我正在从Java类获取对象的数组列表,我想将此数组列表传递给javascript函数,并在javascript函数中获取每个对象的属性。

Please help me how to extract the value of the attributes inside the object. 请帮助我如何提取对象内部属性的值。

Following is the code which I am using 以下是我正在使用的代码

`<script type="text/javascript">
var stats=new Array();
var i=0;
<%JobStats jobstat=new JobStats();
ArrayList<JobStats> stats=jobstat.Consolidate();
for(int i=0;i<stats.size();i++)
{
%>
stats[i]="<%=stats.get(i)%>";
i=i+1;
<%}%>
loadstats(stats);
</script>`
/* Javascript function*/
var array=new Array();
function loadstats(stats)
{

    array=stats[0];
    for(var key in array)
        {
        document.write(array[key]);
        }

}

One of the ways to comunicate betweet Java and javascript is using JSON. 交流更好的Java和javascript的方法之一是使用JSON。 Javascript supports JSON natively in most modern browsers and in Java you can use Simple JSON Javascript在大多数现代浏览器中都原生支持JSON,而在Java中,您可以使用简单JSON

You can transfer JSON Objects an Arrays between both languages. 您可以在两种语言之间传输JSON对象和数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM