data{
clinic:[
{
province:"广西壮族自治区",
city:"玉林市",
name:"玉林市第一人民医院",
longitude:1,
latitude:2,
},
{
province:"广西壮族自治区",
city:"玉林市",
name:"博白县人民医院",
longitude:11,
latitude:22,
}
],
}
qqmapsdk = new QQMapWX({
key: ''
});
that.data.clinic.forEach(element => {
var loc = element.province + element.city + element.name
console.log(loc)
qqmapsdk.geocoder({
address:loc,
success:function(res){
var la = "element.latitude"
var lo = "element.longitude"
that.setData({
[la]:res.result.location.lat,
[lo]:res.result.location.lng
})
console.log(res.result.location.lat)
console.log(element.latitude)
}
})
});
const that = this;
that.data.clinic.forEach((element) => {
var loc = element.province + element.city + element.name;
const timer = setTimeout(()=>{
clearTimeout(timer);
element.latitude = '2222222'
element.longitude = '33333333'
},1000);
});
that.setData({
clinic: that.data.clinic
});
console.log(that.data.clinic);
这么统一赋值即可
赋值方法错了吧,setData貌似要从data层往里找,你这直接过滤掉clinic了
请学会如何「提问」(👈戳我)
for(var i=0;i<that.data.clinic.length;i++){
var clinicloc = that.data.clinic[i].province + that.data.clinic[i].city + that.data.clinic[i].name
qqmapsdk.geocoder({
address:clinicloc,//成功
success:function(res){
var c_lng = "clinic[" + i + "].longitude"
var c_lat = "clinic[" + i + "].latitude"
var lng = res.result.location.lng
var lat = res.result.location.lat
that.setData({
[c_lng]:lng,
[c_lat]:lat
})
console.log(lng,lat)
console.log(that.data.clinic)
},
fail:function(res){
console.log(res)
}
})
};
请学会如何「提问」(👈戳我)
请学会如何「提问」(👈戳我)