<script type="text/ecmascript">
var fls = {
"8":{"pn":"西游记","no":3},
"11":{"pn":"西游记","no":6},
"14":{"pn":"西游记","no":9},
"15":{"pn":"西游记","no":10},
"12":{"pn":"西游记","no":7},
"7":{"pn":"西游记","no":2},
"6":{"pn":"西游记","no":1},
"10":{"pn":"西游记","no":5},
"13":{"pn":"西游记","no":8},
"9":{"pn":"西游记","no":4}
};var objSort = function (obj) {
var a = [], temp = {}, i;
for (i in obj) a.push(i);
a.sort(function (a, b) {
return b - a;
});
while (a.length > 0) {
i = a.pop(), temp[i] = obj[i];
}
return temp;
};fls = objSort(fls);var a = [], i;for (i in fls) a.push(i);alert(a.join("\n"));
</script>
我把原对象的成员给删除掉,然后按照顺序重新加,竟然不理我..伤心之下,就clone一层了一个源对象...
objSort : function (obj,sortType){
var tempObj = {};
var tempArray = [];
var type = typeof sortType
for(var i in obj){
tempArray.push(i);
}
switch(type){
case "number" :
tempArray.sort(copmare);
break;
}
for(var j=0; j<tempArray.length;j++){
tempObj[tempArray[j]] = obj[tempArray[j]];
}
return tempObj;
}
function copmare(a,b){
return a - b;
}
调用this.objSort(obj,1)