简体   繁体   English

在JavaScript数组中存储数据

[英]Storing data in JavaScript array

This is my jsp code where I am trying to push some data in javaScript array. 这是我的jsp代码,我试图在javaScript数组中推送一些数据。

 <%
    int proListSize =  proList.size(); 

ProfileDAO proDAO = null;

            for(int i = 0, j=1; i < proListSize; i++){

                proDAO = (ProfileDAO)proList.get(i);%>

        entireArray.push(<%= proDAO.getNetworkmapId()%> + ":"+<%=proDAO.getAssetId()%> + ":" + <%= proDAO.getCode()%>);

        <%} %>

And this is the function where I am trying to use it by using pop function. 这是我试图通过使用pop函数来使用它的功能。

function GenDemographicTag() {

 var ptag = "<!-- Begin "+networkNameToUpperCase+" -->\n" ;
            var t = "";
             if (WhiteTagLabelDomain) {
                ptag += "<iframe src=\"http://"+WhiteTagLabelDomainTrim+"/jsc/"+folderName+"/dm.html?";
             } else {
                ptag += "<iframe src=\"http://"+cdnName+"/jsc/"+folderName+"/dm.html?";
             }
            ptag += "n="+networkId+";";

            for(var i = 0;i< entireArray.length;i++){
                var combinedString = entireArray.splice(1,1);
                var rightSide = combinedString.split(':')[0];
                var middle = combinedString.split(':')[1];
                var leftSide = combinedString.split(':')[2];
            t = "";
            if ( $("proElementEnable_"+rightSide) && $("proElementEnable_"+leftSide).checked) {
                if ( middle == "1") {
                   if ( $("zip").value.length <= 0) {
                     t = "0";
                    } else {
                  t =  $("zip").value;
                    }
                } else if ( $("targetList_"+rightSide) && $("targetList_"+rightSide).length > 0 &&  $("targetList_"+rightSide).options[0].value != "-1") {
                    t =  makeProelementList($("targetList_"+rightSide));
                 }
                ptag += leftSide+"=" + t+ ";";
            }

             proDAO = null;
            }

            ptag += "\" frameborder=0 marginheight=0 marginwidth=0 scrolling=\"no\" allowTransparency=\"true\" width=1 height=1>\n</iframe>\n<!-- end "+networkNameToUpperCase+"   -->\n";

            document.forms[0].tag.value = ptag;

        }

Basically I am trying to get the data from proList and store it in javaScript array(entireArray)...so that I can use in the javascript function..but after doing the above I get a javaScript error as follow: 基本上我试图从proList获取数据并将其存储在javaScript数组(wholeArray)中...以便我可以在javascript函数中使用..但在执行上述操作后,我得到一个javaScript错误,如下所示:

entireArray.push(3 + ":"+3 + ":" + d3);

entireArray.push(185 + ":"+5 + ":" + d4);

entireArray.push(2 + ":"+2 + ":" + d2);

entireArray.push(186 + ":"+5 + ":" + d9);

entireArray.push(183 + ":"+5 + ":" + d6);

entireArray.push(184 + ":"+5 + ":" + d7);

entireArray.push(187 + ":"+5 + ":" + da);

entireArray.push(445 + ":"+5 + ":" + db);

Reference Error:d3 is not defined.  

what is the exact problem..? 什么是确切的问题..?

The return type of splice is an ARRAY , so you can try following code splice的返回类型是ARRAY,因此您可以尝试以下代码

var combinedString = entireArray.splice(1,1);
var rightSide = combinedString[0].split(':')[0];
var middle = combinedString[0].split(':')[1];
var leftSide = combinedString[0].split(':')[2];

d3 should be in quotes. d3应该用引号括起来。 "d3"

You need to put the out of JSP in quotes. 您需要将JSP从引号中删除。

entireArray.push(<%= proDAO.getNetworkmapId()%> + ":"+<%=proDAO.getAssetId()%> + ":" + '<%= proDAO.getCode()%>');

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

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