angular - 如何像 typescript 中的数组一样解析 Json 对象。 MAP firestore 内的 MAP

标签 angular google-cloud-firestore angularfire2 angular8

我想像数组一样解析driverDocumentDetails

JSON是从android (Java) HashMap数据结构实现的 MAP 内的 Angular Firestore MAP

{ 
   "driverDocumentDetails":{ 
      "fhgfh":{ 
         "documentCategoryID":"fhgfh",
         "documentCategoryName":"Pan Card",
         "documentUploadedDateTime":null,
         "reasonForRejection":null,
         "uploaded":false,
         "uploadedDocumentURL":null,
         "verified":false
      },
      "bjhbh":{ 
         "documentCategoryID":"bjhbh",
         "documentCategoryName":"Driving License",
         "documentUploadedDateTime":null,
         "reasonForRejection":null,
         "uploaded":false,
         "uploadedDocumentURL":null,
         "verified":false
      },
      "hgvjh":{ 
         "documentCategoryID":"hgvjh",
         "documentCategoryName":"NOC",
         "documentUploadedDateTime":null,
         "reasonForRejection":null,
         "uploaded":false,
         "uploadedDocumentURL":null,
         "verified":false
      }
   },
   "driverID":"bhbjhbjhbj",
   "hgchg":[ 
      { 
         "bjnk":"jhbjhb",
         "fhfyhgf":"jjb"
      },
      { 
         "gfhg":"jgjuy",
         "gh":"guguj"
      }
   ]
}
onCustom(recordRow) {
    console.log("onCustom Driver docs data---->",recordRow);
    this.crudService.ReadDriverDocuments(recordRow.data.id).subscribe(data => {

    this.driverDocument = data.data();
    console.log('ReadDriverDocuments',this.driverDocument);
    });
  }

最佳答案

您可以使用Object.keys获取键,然后将其映射到新数组中:

var driverDocumentDetailsArray = Object.keys(this.driverDocument.driverDocumentDetails)
    .map(key => this.driverDocument.driverDocumentDetails[key]);

或者如果可用,只需Object.values

var driverDocumentDetailsArray = Object.values(this.driverDocument.driverDocumentDetails);

关于angular - 如何像 typescript 中的数组一样解析 Json 对象。 MAP firestore 内的 MAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58505470/

相关文章:

AngularFire2 - 通过 Observable 删除项目 - 最后一个项目不会从 UI 中删除

Angular2 - 除非单击,否则不会显示更改检测

css - Rxjs 鼠标事件以在 Angular 6 中实现所需的功能

javascript - 如何以编程方式将 ngBootstrap 弹出窗口添加到元素?

python - 为什么 Firestore 对 64 位整数进行舍入?

node.js - 如何在Firebase云功能中使用adminSdk为firestore文档创建文档ID?

javascript - 我可以将 .then() 与 firebaseListObservable 一起使用吗,即 this.items = query 和 .then()

Angular 2 : Why do I need classes like Hero. ts?

node.js - Web 应用程序(API 和前端)- 路由设计

firebase - 如何设计 Cloud Firestore 数据库架构