一个数组
var scheduleList = [Object, Object, Object, Object, Object, Object]
Object = {
leftNum:36
outCallType:"DEPT_COMMON"
price:"12.00"
regDate:"2017-07-19"
regTime:"MORNING"
remark:"有"
rest:false
scheduleId:93700
weekDay:"周三"
}
这里有个需求 根据regTime属性按照
E_MORNING MORNING NOON AFTERNOON EVENING ALLDAY排序
scheduleList.sort(function(a,b){
var lt = 0,rt = 0;
switch (a.regTime) {
case 'E_MORNING':
lt = 0;
break;
case 'MORNING':
lt = 1;
break;
case 'NOON':
lt = 2;
break;
case 'AFTERNOON':
lt = 3;
break;
case 'EVENING':
lt = 4;
break;
case 'ALLDAY':
lt = 5;
break;
}
switch (b.regTime) {
case 'E_MORNING':
rt = 0;
break;
case 'MORNING':
rt = 1;
break;
case 'NOON':
rt = 2;
break;
case 'AFTERNOON':
rt = 3;
break;
case 'EVENING':
rt = 4;
break;
case 'ALLDAY':
rt = 5;
break;
}
return lt - rt;
});
经过以上操作就可以完成了