日期:2014-05-16  浏览次数:20469 次

JK_10000版主请进
我看了你的一个帖子
if(true)//按字符串排序,如果数据量很大可以这样
{
var d1=new Date();定义这个对象的意义是什么呢
var tempA=new Array();
for(var i=a.length-1;i >-1;i--){
tempA[i]=a[i][0];
tempA[i].objddValue=a[i];
alert(tempA[i].objddValue)是undefined的,为什么呢

}
tempA.sort();
for(var i=a.length-1;i >-1;i--){
tempA[i]
a[i]=tempA[i];
tempA[i].objValue=tempA[i].objValue;的目的是什么意思呢
}
tempA=null;
alert(a.length+ "--- "+(new Date()-d1));
}
alert(a)
</script >
谢谢

------解决方案--------------------
以前的代码有误,你看这一个吧:

<html>

<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> New Page 2 </title>
</head>

<body>
自己调整a的长度,和if里的false/true,进行比较
</body>

</html>
<script >
var a=[[ "62 ", "ccc ", "12 "],
[ "59 ", "study ", "8 "],
[ "61 ", "aaa ", "12 "],
[ "13 ", "商务部1组1 ", "5 "],
[ "1 ", "研发部 ", "12 "],
[ "3 ", "研发部2组 ", "1 "],
[ "4 ", "商务部 ", "12 "],
[ "55 ", "aa ", "54 "]];

var d1=new Date();;

if(false)//按字符串排序,如果数据量少于2000可以这样
{
a.sort(function(a1,a2){return (a1[0] > a2[0])?1:-1;});
}
else //按字符串排序,如果数据量很大可以这样
{
var tempA=new Array();
for(var i=a.length-1;i > -1;i--){
tempA[i]=new String(a[i][0]);
tempA[i].objValue=a[i]; //String对象加自定义属性,将需要排序的对象附在String对象上
}
tempA.sort(); //对String对象数组排序
for(var i=a.length-1;i > -1;i--) a[i]=tempA[i].objValue; //将附在排序好的String对象上的自定义属性取回到数组A

}
alert(a.length+ "--- "+(new Date()-d1));
//alert(a.join( "\n "));
//
</script >