为什么我的javascript数组从java对象中获取未定义的值?

时间:2021-12-19 16:31:15

Hey guys this must be a silly question for some of you, but I can't go through this problem. I'm trying to pass values from my java object to a javascript array. For some reason it doesn't work. The CanchasPrecios2 Arrays get filled out with undefined values, and won't let me work. The CanchasDescription do get the right values. I've tripled check to see what are the values for the object's price and they are the right ones. Both Price and Descriptions are Strings in their Java Object. Any idea on how to solve it?

嘿伙计们,这对你们中的一些人来说一定是个愚蠢的问题,但我无法解决这个问题。我正在尝试将值从java对象传递到javascript数组。由于某种原因,它不起作用。 CanchasPrecios2数组中填充了未定义的值,不会让我工作。 CanchasDescription确实获得了正确的价值观。我已经三次检查以查看对象价格的值是什么,它们是正确的。价格和描述都是Java对象中的字符串。有关如何解决它的任何想法?

THANKS!

   var y = <%=param%>;
   var CanchasDescription = new Array();
   var CanchasPrecios2 = new Array();

   <% for(int i =0; i<owner.getMisCanchas().size(); i++)
    { %>

    CanchasDescription[<%=i%>] = <%= owner.getMisCanchas().get(i).getDescription()%>;
    CanchasPrecios2[<%=i%>] = <%=owner.getMisCanchas().get(i).getPrice()%>; 

   <%}%>

2 个解决方案

#1


2  

I do now know JSP very well, but aren't you missing the quotes around your printed values from Java? I suppose your code should be something like this:

我现在对JSP非常了解,但是你不是错过了Java中打印值的引号吗?我想你的代码应该是这样的:

CanchasDescription[<%=i%>] = "<%= owner.getMisCanchas().get(i).getDescription()%>";
CanchasPrecios2[<%=i%>] = "<%=owner.getMisCanchas().get(i).getPrice()%>";

Take a look at the source code on your browser and see how the javascript code was generated.

查看浏览器上的源代码,看看如何生成javascript代码。

#2


0  

I got it solved guys, apparently I had a silly mistake after this code that made it undefined. Sorry about that guys. Also just wanted to remind you that there is no need of the quotes, it won't affect in anything as long it is a String. Thanks You very much!

我得到了解决的问题,显然我在这段代码之后犯了一个愚蠢的错误,使得它未定义。抱歉,那些家伙。还只是想提醒你,不需要引号,只要它是一个String就不会影响任何东西。非常感谢你!

#1


2  

I do now know JSP very well, but aren't you missing the quotes around your printed values from Java? I suppose your code should be something like this:

我现在对JSP非常了解,但是你不是错过了Java中打印值的引号吗?我想你的代码应该是这样的:

CanchasDescription[<%=i%>] = "<%= owner.getMisCanchas().get(i).getDescription()%>";
CanchasPrecios2[<%=i%>] = "<%=owner.getMisCanchas().get(i).getPrice()%>";

Take a look at the source code on your browser and see how the javascript code was generated.

查看浏览器上的源代码,看看如何生成javascript代码。

#2


0  

I got it solved guys, apparently I had a silly mistake after this code that made it undefined. Sorry about that guys. Also just wanted to remind you that there is no need of the quotes, it won't affect in anything as long it is a String. Thanks You very much!

我得到了解决的问题,显然我在这段代码之后犯了一个愚蠢的错误,使得它未定义。抱歉,那些家伙。还只是想提醒你,不需要引号,只要它是一个String就不会影响任何东西。非常感谢你!