我想通过阵列进行迭代,并希望使后续的API调用,并且,以显示元件的相关值
currentRefValue: any = [];
myArray.droppeditem = [];
somearray.forEach(element => {
let objTemp:any = {}
objtemp.receivedValue =
someFunction(element.elementId,element.elementName)
myArray.droppeditem.push(objTemp);
})
someFunction(eId,ename){
let parentObj = this.getExisitingParentObj(eId);
let parentEquip = parentObj.map(equip => equip.entities.filter(entity =>
entity.entities.length > 0)[0])[0];
let ref = this.helperService.getPointId(this.someExisitngObject,
['current', 'desired'], parentEquip.referenceIDs)[0];
let subs = this.siteService.getPointData(ref, 'current')
.pipe(
map(this.helperService.stripHaystackTypeMapping),
)
.subscribe(({ rows }) => {
if (rows.length > 0) {
this.currentRefValue[ename] = rows[0].val;
}
});
//someCalculations
return this.currentRefValue;
}
随后的API调用(this.siteService.getPointData)预期从之前的API调用(this.helperService.getPointId)和先前(this.helperService.getPointId)值inturn已经parentEquip对象。 我想从里面foreach循环调用someFunction,因为我必须让每个元素的currentRefValue
HTML
<div *ngFor="let existingItem of myArray.droppeditem">
<span>existingItem.receivedValue</span>
</div>