Angular 如何得到迭代对象,它在数组中,该数组也在另一个数组中

Angular 如何得到迭代对象,它在数组中,该数组也在另一个数组中,angular,Angular,如何确定sumPrice值在我的例子中,它向我展示了未定义的您试图计算一些甚至还没有被评估的结果 objArray将异步填充,并且在执行this.objArray.forEach((outer,index)=>{…})函数之后也会异步填充 您应该做的是,只在填充整个objArray之后计算总和。为此,您可以使用并等待所有this.billingservice.getbill(this.formatDate(wdate))调用发生。完成后,您可以从返回的数组中计算总数 大概是这样的: this.w

如何确定sumPrice值在我的例子中,它向我展示了未定义的

您试图计算一些甚至还没有被评估的结果

objArray
将异步填充,并且在执行
this.objArray.forEach((outer,index)=>{…})
函数之后也会异步填充

您应该做的是,只在填充整个
objArray
之后计算总和。为此,您可以使用并等待所有
this.billingservice.getbill(this.formatDate(wdate))
调用发生。完成后,您可以从返回的数组中计算总数

大概是这样的:

this.weekDates.forEach((wdate) => {
  this.billingservice.getbill(this.formatDate(wdate)).subscribe(info => {
    this.objArray.push(info)
    // console.log(info)
  })
  // console.log((wdate));
})
this.objArray.forEach((outer, index) => {
  console.log(outer, "outerloop-", index);
  outer.forEach(inner => {
    // this.sumPrice = inner.grandTotol
    this.sumPrice = this.sumPrice + (inner.grandTotol)
    console.log(inner.grandTotal, "innerloop")
  });
});
这里有一个供您参考


您正在尝试计算尚未评估的结果

objArray
将异步填充,并且在执行
this.objArray.forEach((outer,index)=>{…})
函数之后也会异步填充

您应该做的是,只在填充整个
objArray
之后计算总和。为此,您可以使用并等待所有
this.billingservice.getbill(this.formatDate(wdate))
调用发生。完成后,您可以从返回的数组中计算总数

大概是这样的:

this.weekDates.forEach((wdate) => {
  this.billingservice.getbill(this.formatDate(wdate)).subscribe(info => {
    this.objArray.push(info)
    // console.log(info)
  })
  // console.log((wdate));
})
this.objArray.forEach((outer, index) => {
  console.log(outer, "outerloop-", index);
  outer.forEach(inner => {
    // this.sumPrice = inner.grandTotol
    this.sumPrice = this.sumPrice + (inner.grandTotol)
    console.log(inner.grandTotal, "innerloop")
  });
});
这里有一个供您参考

什么是
console.log(外部,“outerloop-”,索引)打印?而
internal
会是什么样子,inner
outer.forEach
?console.log(outer,“outerloop-”,index)是什么打印?那么
内部
会是什么样子,内部
外部。forEach?