【求助】数组内按照某个字段进行排序失败?
数组如下。
- 0:
- wasteAddress: "上海虹桥站"
- wasteLat: "31.194106239"
- wasteLon: "121.32066572"
- wasteNumber: 3
- wasteUnit: "大桶"
- wasteaccepted: true
- wastedistance: 24120
- 1:
- wasteAddress: "上汽大众汽车有限公司一厂"
- wasteLat: "31.303136698"
- wasteLon: "121.169769349"
- wasteNumber: 3
- wasteUnit: "大桶"
- wasteaccepted: false
- wastedistance: 17572
采用如下代码排序,但是排序失败,打印出来的数值是0.想问一下具体原因是什么?
_this.data.wastelist.sort(function(a,b) {
console.log(a.wastedistance)
return (a.wastedistance-b.wastedistance)
});