1.日期排序
vardata = {
"rows": [{
"name": "张三",
"time": "2011/4/1 0:00:00",
},{
"name": "李四",
"time": "2015/5/6 12:30:00",
},{
"name": "王五",
"time": "2012/10/1 22:10:00",
},{
"name": "赵六",
"time": "2011/9/1 22:10:00",
}]
};
var rows = data.rows;
rows.sort(function(a,b){
returnDate.parse(a.time) - Date.parse(b.time);//时间正序
});
for(vari =0,l=rows.length;i<l;i++){
console.log(rows[i].name + " | "+ rows[i].time);
}
2.字符串排序(中文)
var jsonStr = {"data":[{"deptId":"7","deptName":"医学美容中心"},{"deptId":"8","deptName":"五官科"},{"deptId":"11231","deptName":"康复理疗室(东)"},{"deptId":"1","deptName":"内科"},{"deptId":"2","deptName":"医学"},{"deptId":"11240","deptName":"心血管内科病区(东)"},{"deptId":"4","deptName":"儿科"},{"deptId":"11","deptName":"泌尿外科"},{"deptId":"3","deptName":"妇产科"},{"deptId":"5","deptName":"急诊"},{"deptId":"12","deptName":"健康医学中心"}],"status":"true","msg":"成功"};
let data = jsonStr.data.sort(function(a, b) {
return a.deptName<b.deptName?-1:(a.deptName>b.deptName?1:0);
});
3.获取请求信息
//获取当前网址,
var curPath = window.document.location.href;
//获取主机地址之后的目录,
var pathName = window.document.location.pathname;
var pos = curPath.indexOf(pathName);
//获取主机地址
var localhostPaht = curPath.substring(0, pos);
//获取带"/"的项目名,
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
网友评论