如何在angular6中进行两个不同的数组结果操作

How to do a two different array results manipulation in angular6

这是产品服务响应。

productServiceResponse = [
  {productOrderId:108898,productStatus:"C",productId:'4'},
  {productOrderId:108899,productStatus:"P",productId:'2'},
];

通过使用常量值 currentProductStatus = "C";

在产品服务响应中,我需要找到当前产品并使用上述常量值获取产品并获取产品ID。

所以我在这里做了那个。在这里我做了当前产品的索引,而不是在 dynamyllay 中从集合中找到需要它的索引。

this.productServiceResponse[0].productStatus

// 查看当前商品

  const ProductCode =
            this.productServiceResponse[0].productStatus ===
            this.currentProductStatus
              ? this.productServiceResponse[0].productId.toString()
              : null;

一次获取当前的productId。

我已经在另一个合集中查过了。

      productTypes =[
    {id: "1", name: "Laptop"},
    {id: "2", name: "Mobile"},
    {id: "3", name: "headphone"},
    {id: "4", name: "Cameras"}
      ];

从产品类型集合中,我匹配了上述结果中的产品 ID。

   this.currentProduct = this.productTypes.find(product=>product.id ===ProductCode).name;

最后o/p变成相机

我得到了 o/p :但我需要在单行过滤而不是两个变量中进行查询。

任何人都可以重构这个。

演示:filter

试试这个方法

this.productTypes.find(product=>
    product.id === productServiceResponse.find(psr=>psr.productStatus === this.currentProductStatus).productID
    ).name 

请注意,我在我的单元格中输入了这个 phone