Sfoglia il codice sorgente

距离排序

soldDate
HolyKnightIX 2 anni fa
parent
commit
51366c1fac
1 ha cambiato i file con 36 aggiunte e 3 eliminazioni
  1. +36
    -3
      index/index.js

+ 36
- 3
index/index.js Vedi File

@@ -626,7 +626,30 @@ Page({
console.log(error);
},
complete: finish => {
const latitudeNow = that.data.locateData.latitude
const longitudeNow = that.data.locateData.longitude

const mallLocationArr = []
let index = 0
that.data.shopList.forEach(item => {
const obj = {
latitude: item.latitude,
longitude: item.longitude,
mallTenantId: item.tenantId,
index: index
}
mallLocationArr.push(obj)
index++
})

const isBest = []
mallLocationArr.forEach(item => {
const num = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude)
isBest.push(num.distance_str)
})
console.log(isBest, 'isBest');
const winer = isBest.bubbleSort()
console.log(winer, 'winer');
}
})

@@ -667,8 +690,6 @@ Page({
return objData
},



onShow: function () {
this.mallSync()
console.log(app.globalData.mouldType, "mouldType")
@@ -1442,4 +1463,16 @@ Page({
}
};
}
});
});

Array.prototype.bubbleSort = function () {
for (let i = 0; i < this.length - 1; i += 1) {
for (let j = 0; j < this.length - 1 - i; j += 1) {
if (this[j] > this[j + 1]) {
const temp = this[j];
this[j] = this[j + 1];
this[j + 1] = temp;
}
}
}
}

Caricamento…
Annulla
Salva