- Array sort()
– To sort “xxx” first, the second is “yyy”
var arr = []
arr.push({
"xxx":"xx",
"yyy":"yy",
"zzz":"zz"
})
arr.sort(function(a,b){
if(a.xxx === b.xxx){
return a.yyy >= b.yyy ? 1 : -1
}
return a.yyy >= b.yyy ? 1:-1
})
- Object Array (JSON) delete by key
var persons = [];
var person={name:"yaoMing",sex:"m",age:"26"};
persons.push(person);
persons.unshift(person);
persons.pop();
persons.shift();
persons.splice(0,1);
var self={id:"001",name:"tom",sex:"m",age:"24"};
var brother={name:"Mike",sex:"m",age:"29"};
persons.splice(1,0,self,brother);
var self={id:"002",name:"tom",sex:"m",age:"24"};
var brother={name:"Mike",sex:"m",age:"29"};
persons.splice(id:"003",0,1,self,brother);
var delID = "002";
for(var index = persons.length - 1; index >= 0; index--){
if(persons[index].id === delID || persons[index].id === ""){
persons.splice(index,1);
}
}
this.getDate = function(){
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() +1;
var day = date.getDate();
var hour = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
var myDate = (day < 10 ? "0" + day : day) + "-" +
(month < 10 ? "0" + month : month) + "-" + year + " " +
(hour < 10 ? "0" + hour : hour) + ":" +
(minutes < 10 ? "0" + minutes : minutes) + ":" +
(seconds < 10 ? "0" + seconds : seconds);
return myDate;
}
this.showLoading = function(){
try{
var div = $("#loading-div");
if(div.length === 0){
$("body").append(this.dialog.loading_content);
div = $("#loading-div");
}
div.css('visibility','visible');
div.show();
$("body").css("cursor","not-allowed");
}catch(ex){
}
}
this.dialog = {
loading_content : "<div id='loading-div' style='background: rgb(255,255,255);left:0px;top:0px;width:100%;height:100%;right:10px;display:none;visibility:hidden;position:fixed;z-index:1000;opacity:0.5;'>"+
"<img style='left:50%;top:50%;display:block;position:fixed;transform:translate(-50%,-50%);' alt='loading' src='" +
GLOBAL.Path + "/image/loading.gif'/>" + "</div>",
showLoading : function(){
var div = $("#loading-div");
if(div.length === 0){
$("body").append(this.dialog.loading_content);
div = $("#loading-div");
}
div.css('visibility','visible');
div.show();
$("body").css("cursor","not-allowed");
},
closeLoading : function(){
$("#loading-div").hide();
$("#loading-div").css('visibility','hidden');
$("body").css("cursor","auto");
}
}
GLOBAL.MyCommon = new Common();