Angular Rxjs:无法访问订阅中的数组元素

Angular Rxjs:无法访问订阅中的数组元素,angular,ionic2,rxjs,angularfire2,Angular,Ionic2,Rxjs,Angularfire2,我正在我的Ionic应用程序中检索AngularFireStoreCollection,方法如下 this.analysisProvider.getAllOrders().valueChanges() .map(ordercoll=>ordercoll) .pipe(mergeMap(orddoc=>orddoc)).map(ord=>ord.orderdetails).map(res=>res) .subscribe(val=>{ console.log(

我正在我的Ionic应用程序中检索AngularFireStoreCollection,方法如下

this.analysisProvider.getAllOrders().valueChanges()
 .map(ordercoll=>ordercoll)
 .pipe(mergeMap(orddoc=>orddoc)).map(ord=>ord.orderdetails).map(res=>res)
 .subscribe(val=>{
 console.log('res=',val);  
})
console.log提供以下输出

现在,我实际上想要访问partprice属性,应用过滤器和reduce以从所有文档中获取总值。但是,我无法访问subscribe函数中的val值。我试着在订阅中跟随

  • log('val=',val.partprice); 输出:val=未定义

  • val.forEach(v=>console.log('val=',v.partprice))
    输出:类型“{partname:string;partcode:string;数量:number;revisedquantity:number;duedate:any;re…”上不存在属性“forEach”

  • 我不知道我还应该做什么。
    理想情况下,我希望在订阅之前映射筛选器和reduce,并使用subscribe only将最终输出分配给变量。实现这一点的任何建议都是非常受欢迎的。

    val是一个项目数组,您试图访问数组中项目的属性。您正在查找
    console.log(val[0].partprice)
    val.forEach(item=>console.log(item.partPrice))
    您可以这样做:

    ...
    .flatMap(order => order)
    .map(order => order.partprice)
    .filter(price => price > 0)
    .reduce((acc, value) => acc + value)
    .subscribe(result => console.log(result))
    
    被观察者必须完成以减少工作量。
    平面映射将数组映射到单个事件,以便可以由反应函数处理它们。

    我无法使用val[0]。partprice,因为可能有多个。已尝试过val.forEach(item=>console.log(item.partprice))。获取错误:类型“”上不存在属性“forEach”{partname:string;partcode:string;quantity:number;ReviedQuantity:number;duedate:any;re…'。这是我实际启动的方式,但出现错误并转移到其他选项。错误:类型为“”的flatmap参数上的Typescript错误('顺序:{partname:string;partcode:string;…'不能分配给参数{类型{}上不存在映射属性“partprice”上的类型脚本错误。analysisProvider.getAllOrders()返回什么类型的值更改?它应该类似于:ObservableTheChain on valueChanges()在中间步骤中返回一个数组。在此之前,我分配了一个数组变量,并在所需阶段使用map/filter/reduce处理数组。这解决了问题。感谢您的输入。