<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
//
var willSort = [
{
'name':'a',
'age':21,
'height':'170',
'date':'2014-10-12'
},
{
'name':'b',
'age':19,
'height':'170',
'date':'2014-10-13'
},
{
'name':'c',
'age':22,
'height':'170',
'date':'2014-10-14'
},
{
'name':'d',
'age':2,
'height':'170',
'date':'2014-10-15'
},
{
'name':'e',
'age':30,
'height':'170',
'date':'2014-10-16'
}
];
//alert(willSort[0].date)
/*
@function JsonSort 对json排序
@param json 用来排序的json
@param key 排序的键值
*/
function JsonSort(json,key){
//console.log(json);
for(var j=1,jl=json.length;j < jl;j++){
var temp = json[j],
val = temp[key],
i = j-1;
while(i >=0 && json[i][key]>val){
json[i+1] = json[i];
i = i-1;
}
json[i+1] = temp;
}
//console.log(json);
return json;
}
var json = JsonSort(willSort,'date');
//console.log(json);
// alert(json.length)
for(var i=0;i<json.length;i++){
alert(json[i].date)
//var date=(json[i].date)
// function formatDate(now) {
// now=now.replace(//Date(/,"").replace(/000)//,"");
// now= new Date(parseInt((now*1000).toLocaleString().substr(0,24)));
// var year=now.getFullYear();
// var month=jia0(now.getMonth()+1);
// var date=jia0(now.getDate());
// var hour=jia0(now.getHours());
// var minute=jia0(now.getMinutes());
// var second=jia0(now.getSeconds());
// return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
// }
//function jia0(n){
// if(n<10)
// n="0"+n;
// return n;
//}
//var date="/Date(1410340800000)/";
//document.write(formatDate(date));
}
</script>
</head>
<body>
</body>
</html>