if (res.result.list.length == 0) {
this.setData({
isloding: false
})
}
res.result.list.forEach((item, index) => {
item.phoneinput = item.phoneinput.toString().slice(0, 3) + '****' + item.phoneinput.toString().slice(-4);
if (item.openID === this.data.myStorageOpenid) {
item.OffShelf = true
}
QQMap.calculateDistance({
to: [{
latitude: item.latitude, //商家的纬度
longitude: item.longitude, //商家的经度
}],
success: res => {
let hw = res.result.elements[0].distance //拿到距离(米)
hw = (hw / 1000).toFixed(2) + '公里'
item.hw = hw
}
})
})
let newdata = [...this.data.index_list, ...res.result.list]
this.setData({
index_list: newdata
})
wx.hideLoading()
wx.stopPullDownRefresh()
console.log(newdata)
我想实现列表显示距离,现在出现的问题是:必须上拉加载后才会显示,页onload 不显示。请大神指教!!
异步问题 代码不是按顺序执行的
let list = [
{id: 1},
{id: 2}
]
// 模拟获取经纬度
function mapService() {
return new Promise((relove, reject) => {
setTimeout(() => {
relove({
jd: 1,
wd: 1
})
})
})
}
async function onLoad() {
for(let i = 0; i < list.length; i += 1) {
let {jd, wd} = await mapService();
list[i].jd = jd;
list[i].wd = wd;
}
console.log(list)
}
onLoad();