Я реализую веб-приложение, и мне нужно кодировать некоторые шаги в асинхронном режиме. На одном из этих шагов я вызываю API для извлечения списка идентификаторов из 3D-модели, затем мне нужно использовать это как Обещание, чтобы выполнить еще одну операцию с этими извлеченными идентификаторами.
У меня возникают проблемы при попытке реализовать асинхронность, во второй функции идентификаторы не принимаются должным образом.
Я пытался реализовать обещания и обратные вызовы, но безуспешно.
javascript
//Create bimIdsList Promise in order to create a list with all BIM360
//elements in the model
function bimIdsList() {
self.viewer.model.getBulkProperties(ids, properties, (propResults) => {
propResults.forEach((propResult) => {
propResult.properties.forEach((property) => {
if(property.displayCategory === 'BIM 360'){
self._bimIds.push(propResult.dbId);
}
})
})
});
/*if(self._bimIds) {
resolve();
}*/
return Promise.resolve(self._bimids);
}
//Create fillEquipList function in order to fill equipment list after
//generating bimIdsList
function fillEquipList(bimIds) {
self.viewer.model.getBulkProperties(bimIds, ['Type'], (propResults) => {
propResults.forEach((propResult) => {
propResult.properties.forEach((property) => {
if(property.displayCategory === 'BIM 360') {
var foundEqIndex = self._equipList.findIndex(x => x == property.displayValue);
if(foundEqIndex >= 0) {
//Already in List, do Nothing
} else {
self._equipList.push(property.displayValue)
self._addedEquipment = true;
//Add to dropdown
const optionElement = document.createElement('option');
optionElement.value = property.displayValue;
optionElement.innerText = property.displayValue;
self._selEquipmentType.append(optionElement);
}
}
})
})
});
//Resolve after callback
return Promise.resolve(self._addedEquipment);
}
//Now execute both functions
bimIdsList()
.then(success => {
console.log('bimIds length: ');
console.log( JSON.parse(JSON.stringify(success)) )
return fillEquipList(success)
})
.then(success => this.fillDictionaries());
console.log(this._bimIds);
Я хотел бы выполнить вторую функцию (fillEquipList) с соответствующим параметром, полученным из исходного Promise (bimIds)