在vue中引用了高德地图,用markerList渲染数据点,在getInfoWindow的时候怎么插入一个异步操作?
普通的话是这样出个弹窗:
initMarkerList() {
let _this = this;
map.clearMap();
AMapUI.loadUI(["misc/MarkerList", "overlay/SimpleInfoWindow"], function(
MarkerList,
SimpleInfoWindow
) {
var markerList = new MarkerList({
//其他代码已省略
getInfoWindow: function(data, context, recycledInfoWindow) {
let $data = data.extData;
let str = ``;
if (recycledInfoWindow) {
recycledInfoWindow.setInfoTitle($data["Name"]);
recycledInfoWindow.setInfoBody(str);
return recycledInfoWindow;
}
return new SimpleInfoWindow({
infoTitle: $data["Name"],
infoBody: str,
offset: new AMap.Pixel(0, -20)
});
}
});
markerList.render(_this.markers);
});
},
现在需要异步获取些数据,请问该如何处理?
initMarkerList() {
let _this = this;
map.clearMap();
AMapUI.loadUI(["misc/MarkerList", "overlay/SimpleInfoWindow"], function(
MarkerList,
SimpleInfoWindow
) {
var markerList = new MarkerList({
//其他代码已省略
getInfoWindow: function(data, context, recycledInfoWindow) {
let $data = data.extData;
let str = ``;
_this.$http
.post(_this.page.root + "Cleandot/QueryCleandotModel", {
ID: $data["ID"]
})
.then(data => {
str = `test`;
})
.then(() => {
//请问这里该如何返回?
if (recycledInfoWindow) {
recycledInfoWindow.setInfoTitle($data["Name"]);
recycledInfoWindow.setInfoBody(str);
return recycledInfoWindow;
}
return new SimpleInfoWindow({
infoTitle: $data["Name"],
infoBody: str,
offset: new AMap.Pixel(0, -20)
});
});
}
});
markerList.render(_this.markers);
});
},
自己异步很生疏,麻烦各位大佬指点一下
换了种做法,反正需求做出来就完事了