“await is only valid in async functions and the top level bodies of modules”
(本地使用的時候沒有報錯)
解決方案:
使用await的時候,把這個await包裝在一個async的函數中;
原本的:
let pigeon_models_array = [];
for (var i = 0; i < threeD_models_id_array.length; i++) {
update_loading(threeD_models_id_array.length - i, 0);
var airplaneUri = await Cesium.IonResource.fromAssetId(threeD_models_id_array[i]['id']);
pigeon_models_array.push(airplaneUri);
}
showData(demo_data);
修改之後的:
let pigeon_models_array = [];
async function loadModelOnline(callback)
{
for (var i = 0; i < threeD_models_id_array.length; i++) {
update_loading(threeD_models_id_array.length - i, 0);
var airplaneUri = await Cesium.IonResource.fromAssetId(threeD_models_id_array[i]['id']);
pigeon_models_array.push(airplaneUri);
}
callback(demo_data)
}
loadModelOnline(showData);
但是如果需要順序執行的話,就使用callback;