我试图获取国家/地区名称并将其放入 temparray ,以便我可以使用 temparray 来检查国家/地区(第14行)。问题是 temparray 只能包含一个值,并且在使用temparray.length = 4增加数组长度大小时,热图不会显示在页面中。
以下代码用于检查数组中的重复名称条目。如果重复国家/地区名称,它将添加过去值及其当前值,并将其作为旧行再次添加到数据表中。
var i;
var suq = 0;
var temparray = [""];
var rowcount= 0;
//set the value
for (i = 0; i<count; i++){
var countryname = countryarray[i];
var hostcount = hosthitcount[i];
//document.write("hello");
for (rowcount=0;rowcount<temparray.length;rowcount++){
//check for any repeated country name
if (temparray[rowcount] != countryname){
data.setValue(suq, 0, countryname);
data.setValue(suq, 1, hostcount);
temparray[rowcount] = countryname;
//document.write("win");document.write("<br/>");
suq++;
}else{
//get the hits //rowindex
var pastvalue = data.getValue(rowcount,1);
//add the previous value with current value
var value = parseInt(hostcount)+parseInt(pastvalue);
value+= "";
//document.write(value);
//put it in the table
data.setValue(rowcount,1,value);
// document.write("lose");document.write("<br/>");
}
}
}
答案 0 :(得分:0)
我真的不明白你要对temparray
做些什么。它肯定包含多个带有temparray.push(countryname)
的元素。也许this JavaScript array reference会对你有帮助吗?