let tableData = [
{
date: '04',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 5,
whether: 1
},
{
date: '05',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 5,
whether: 1
},
{
date: '06',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 5,
whether: 0
},
{
date: '07',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 5,
whether: 1
},
{
date: '08',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 5,
whether: 0
},
{
date: '09',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 5,
whether: 1
},
{
date: '11',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 0
},
{
date: '12',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 0
},
{
date: '13',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 1
},
{
date: '14',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 1
},
{
date: '15',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 1
},
{
date: '16',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 0
},
{
date: '17',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 0
},
{
date: '18',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 1
},
{
date: '19',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 1
},
{
date: '20',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 3,
whether: 0
},
{
date: '01',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄',
star: 2,
whether: 0
},
{
date: '02',
name: '王小虎',
address: '上海市普陀区金沙江路 1517 弄',
star: 2,
whether: 0
},
{
date: '03',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄',
star: 2,
whether: 1
},
{
date: '10',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
star: 5,
whether: 1
}
]
tableData.sort((x, y) => {
// 如果星级相同进行 whether 之间的排序
if (x.star === y.star) {
return y.whether - x.whether
} else {
//星级不同时直接以星级进行排序
return y.star - x.star
}
})
数组双重排序的方法
最新推荐文章于 2024-10-11 19:03:40 发布