1、方法
sorts = (element) => {
return function (a, b) {
var value1 = a[element];
var value2 = b[element];
return value1 - value2;
}
}
2.引用
[
{
lastquarterprice: 33,
year: 2022,
materialclass: "塑料",
pricerange: "塑料料箱、废旧信号线等含塑料废旧物资",
sn: 8,
unit: "吨",
collectprice: 102,
marketprice: 850,
quarter: "20",
},
{
lastquarterprice: 33,
year: 2022,
materialclass: "塑料",
pricerange: "塑料料箱、废旧信号线等含塑料废旧物资",
sn: 5,
unit: "吨",
collectprice: 102,
marketprice: 850,
quarter: "20",
},
{
lastquarterprice: 33,
year: 2022,
materialclass: "塑料",
pricerange: "塑料料箱、废旧信号线等含塑料废旧物资",
sn: 1,
unit: "吨",
collectprice: 102,
marketprice: 850,
quarter: "20",
}
]
var 变量 = arr.sort(this.sorts('需要排序的字段'));