Angular 在for循环中看不到控制台日志数据
我有下面的数据集,我正试图循环通过。我也有我的函数,它执行循环,但当我运行应用程序时,我看不到控制台日志Angular 在for循环中看不到控制台日志数据,angular,Angular,我有下面的数据集,我正试图循环通过。我也有我的函数,它执行循环,但当我运行应用程序时,我看不到控制台日志 { "header": { "statuscode": "0", }, "calculateAVAFLoanAdjustment": { "responseCode": null, "responseDescri
{
"header": {
"statuscode": "0",
},
"calculateAVAFLoanAdjustment": {
"responseCode": null,
"responseDescription": null,
"calculatorResults": {
"calculatorResult": [
{
"newCalculatedInstallmentsNo": "63",
"newContractEndDate": "20260725",
"newResidual": "24031.28",
"newInstalment": "5713.38",
"newTerm": "72",
"outBalanceAvaf": null,
"restructureType": "balloon"
}
]
}
}
}
calculateAVAFLoanAdjustment() {
this.avafService.CalculateAVAFLoanAdjustment({accountNumber: '555666'}).subscribe((resp)=>{
this.confirmData = resp.calculateAVAFLoanAdjustment;
for(let i = 0; i < this.confirmData; i++) {
this.calculatorResults = this.confirmData[i].calculatorResults;
console.log("calculatorResults: "+this.calculatorResults)
for(let j = 0; j < this.calculatorResults; j++) {
this.calculatorResult = this.confirmData[i].calculatorResults[j].calculatorResult;
console.log("calculatorResult: "+this.calculatorResult)
}
}
})
}
{
“标题”:{
“状态代码”:“0”,
},
“CalculateAvaloanaadjustment”:{
“响应代码”:空,
“responseDescription”:空,
“计算器结果”:{
“计算器结果”:[
{
“newCalculatedInstallmentsNo”:“63”,
“newContractEndDate”:“20260725”,
“新剩余”:“24031.28”,
“新分期付款”:“5713.38”,
“新术语”:“72”,
“outBalanceAvaf”:空,
“类型”:“气球”
}
]
}
}
}
CalculateAvaFloanaAdjustment(){
this.avafService.calculateAvaFloanaAdjustment({accountNumber:'555666'}).subscribe((resp)=>{
this.confirmData=相应的计算变量调整;
for(设i=0;i
知道控制台日志为什么不打印任何数据吗?假设您总是将
calculatorResult
作为一个数组,我们只需要获取对象上第0个索引处的字段的总和,下面是您可以做的:
试试这个:
calculateAVAFLoanAdjustment() {
this.avafService
.CalculateAVAFLoanAdjustment({
accountNumber: '555666'
})
.subscribe((resp: any) => {
this.calculatorResults =
resp.calculateAVAFLoanAdjustment.calculatorResults;
const [calculatorResult] = this.calculatorResults.calculatorResult;
this.calculatorResult = Object.keys(calculatorResult).reduce(
(acc, key) => {
const value = calculatorResult[key];
if (!isNaN(+value)) {
acc += +value;
}
return acc;
},
0
);
});
}
下面是一个带有解决方案代码的
@SiddAjmera我没有看到任何错误console@SiddAjmera是的,我看到了。我需要另一个解决方案才能进入object,因此您需要
calculatorResult
数组中每个项的所有属性的总和,是吗?@SiddAjmera是的,这是正确的