正序日期排序
const ForwardRankingDate = (data, p) => {
for (var i = 0; i < data.length - 1; i++) {
for (var j = 0; j < data.length - 1 - i; j++) {
console.log(Date.parse(data[j][p]));
if (Date.parse(data[j][p]) > Date.parse(data[j + 1][p])) {
var temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
}
}
}
return data;
}
正序时间戳对比排序
const ForwardRankingtimeStamp = (data, p) => {
for (var i = 0; i < data.length - 1; i++) {
for (var j = 0; j < data.length - 1 - i; j++) {
if (data[j][p] > data[j + 1][p]) {
var temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
}
}
}
return data;
}
倒序日期排序
const ReverseRankingDate = (data, p) => {
for (var i = 0; i < data.length - 1; i++) {
for (var j = 0; j < data.length - 1 - i; j++) {
console.log(Date.parse(data[j][p]));
if (Date.parse(data[j][p]) < Date.parse(data[j + 1][p])) {
var temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
}
}
}
return data;
}
倒序时间戳排序
const ReverseRankingtimeStamp = (data, p) => {
for (var i = 0; i < data.length - 1; i++) {
for (var j = 0; j < data.length - 1 - i; j++) {
if (data[j][p] < data[j + 1][p]) {
var temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
}
}
}
return data;
}
module.exports = {
ReverseRankingDate,
ForwardRankingDate,
ForwardRankingtimeStamp,
ReverseRankingtimeStamp
};
import {
ForwardRankingtimeStamp,
ReverseRankingtimeStamp
} from "@/utils/util.js"
使用实例
computed: {
list2: function() {
var list = []
if (this.ordersStatus == 4 && !this.showm) {
list.push(ReverseRankingtimeStamp(this.list, 'createTime')[ReverseRankingtimeStamp(this.list, 'createTime').length - 1])
} else {
list = this.list
}
return ReverseRankingtimeStamp(list, 'createTime')
}
},