代码如下:
var that = this;
var markerList = [];
db.collection('lost_found').get().then(res => {
var lists = res.data.reverse();
markerList=lists;
for (var i = 0; i < markerList.length; i++) {
that.setData({
'markersObj.id': this.data.markers.length + 1,
'markersObj.longitude': markerList[i].longitude,
'markersObj.latitude': markerList[i].latitude,
})
switch (markerList[i].signName) {
case 'foundThings': that.setData({
'markersObj.iconPath': "../../images/8.png",
'markersObj.callout.content': "失物招领",
'markersObj.callout.color': "#FF3333"
});break;
case 'clubActivity': that.setData({
'markersObj.iconPath': "../../images/10.png",
'markersObj.callout.content': "社团活动",
'markersObj.callout.color': "#FF5511"
});break;
case 'market': that.setData({
'markersObj.iconPath': "../../images/9.png",
'markersObj.callout.content': "二手市场",
'markersObj.callout.color': "#33CCFF"
});break;
}
app.globalData.markerArray.push(this.data.markersObj);
}
}).catch(err => { console.error(err) })
我在onShow里用console.log("长度"+app.app.globalData.markerArray.length)
控制台显示长度为0,我想问一下为什么用setData出回调函数后全局数据就未被修改呢?求好心人给我讲解或者修改一下代码谢谢了!!!!