使用 async await来操作函数异步,函数体内有递归,但是递归还没有完成就执行完了函数。then里面的返回值是个数组但是数组打印的长度是1,但真实长度应该是5,打断点调试res的第一个返回值是一个长度为1的数组,但是紧接着就是长度为5的数组,await不是应该等getAllDownRoteEquipment函数执行完了再返回值吗?请求大神解答 getAllDownRoute(){ viewer.vmethods.getAllDownRoteEquipmentArr().then(function(res){ console.log(res) }) } async getAllDownRoteEquipmentArr(id){ var equipmentArr = []; var selectIds = viewer.getSelection()[0]; await viewer.vmethods.getAllDownRoteEquipment(selectIds,equipmentArr); return equipmentArr; } getAllDownRoteEquipment(id,equipmentArr){ return new Promise(function (resolve) { var aa = (id,equipmentArr)=>{ viewer.getProperties(id,function(res) { for (var i = 0; i < res.properties.length; i++) { if (res.properties[i].displayName == "型号") { var downEquipment = res.properties[i].displayValue; equipmentArr.push(downEquipment); resolve(equipmentArr); viewer.search(downEquipment,(searchId) =>{ aa(searchId[0],equipmentArr) },function(){},"自身标识"); break; } } }) } aa(id,equipmentArr) }) }
添加回答
举报
0/150
提交
取消