以时间排序为例
知识点:js原生数组排序 Array.sort(function(){})
//处理函数
handleSort(obj){
obj.sort((a,b)=>{
let t1 = new Date(Date.parse(a.birthday.replace(/-/g,"/")))
let t2 = new Date(Date.parse(b.birthday.replace(/-/g,"/")))
return t2.getTime()-t1.getTime()
})
return obj
},
如何使用:
let objList=[
{title:"小红", birtyday:'2020-04-05', height:"60"},
{title:"小明", birthday:'2020-06-06', height:"50"},
{title:"小刚", birthday:'2020-05-05', height:"55"}
]
objList=this.handleSort(objList)