如何从外部数据映射深度嵌套的项目数组

时间:2019-06-01 21:04:25

标签: multidimensional-array rxjs

我以前做过一个映射,但是没有深层嵌套。我正在尝试从损坏的数据库中重新填充数据。我已经手动重建了订单数组。我正在尝试查找每个玩家的数据,然后为每个玩家更新字段(以null开头):

示例:我从这样的数据开始:

const orders = [
{
"paymentID": "ch_456", 
"paymentStatus": "PAID", 
"user": "kingkong@gmail.com", 
"cart": {
  "username": "kingkong@gmail.com", 
  "totalQty": 1, 
  "totalPrice": 80, 
  "items": [{
    "event": "Men's BB", 
    "division": "Men's", 
    "level": "BB", 
    "group": "nonpro", 
    "field": "PAL", 
    "day": "Saturday", 
    "numplayers": 2, 
    "price": 80, 
    "players": [{
      "avp_id": 1042641, 
      "first": "King", 
      "last": "Kong", 
      "waivers": [], 
      "completed": true, 
      "country": "USA", 
      "signed": false}, 
      {
      "avp_id": 1086117, 
      "first": "Jacob", 
      "last": "Ladder", 
      "waivers": [], 
      "completed": true, 
      "country": "USA", 
      "signed": false, 
      "shirt_size": "N/A"}], 
    "net": null, 
    "team": null, 
    "notes": null, 
    "paymentNote": null, 
    "waiversSent": false, 
    "active": true, 
    "paymentID": "ch_456", 
    "users": ["kingkong@gmail.com"], 
    "paymentStatus": "PAID", "__v": 4}]},
"__v": 0
},{
"paymentID": "ch_123",
"paymentStatus": "PAID",
"user": "marymac@aol.com",
"cart": {
  "username": "marymac@aol.com", 
  "totalQty": 1,
  "totalPrice": 50,
  "items": [{
    "event": "Junior Boys 16s",
    "division": "Junior Boys",
    "level": "16s",
    "group": "nonpro",
    "field": "Main",
    "day": "Friday",
    "numplayers": 2,
    "price": 80,
    "players": [{
      "avp_id": 1022228,
      "first": "Some",
      "last": "Kid",
      "waivers": [],
      "completed": true,
      "country": "USA",
      "signed": false
      }, {
      "avp_id": 1020142,
      "first": "Justin",
      "last": "Kid",
      "waivers": [],
      "completed": true,
      "country": "USA",
      "signed": false,
      "shirt_size": "N/A"
      }
    ], 
    "net": null, 
    "team": null, 
    "notes": null, 
    "paymentNote": null, 
    "waiversSent": false, 
    "active": true, 
    "paymentID": "ch_123", 
    "users": ["marymac@aol.com"], 
    "paymentStatus": "PAID", "__v": 4
    }
  ]
},
"__v": 0
}];

这是我的代码,我想从API中获取数据,并更新播放器信息以传递到更进一步的函数中:

async getLostData() {
    // get the lost orders
    console.log('start lost data import');
    // this.adminService.GetLostOrders().subscribe(orders => {
    //   console.log('load each order into system', orders);
orders.forEach(order => {
    order.cart.items.map(item => {
      const players = item.players.map(async player => {
         player = await 
           this.adminService.adminAVPReg(player.last, player.avp_id)
           .toPromise(); 
          console.log("updated player outside subscribe", player);
      });
      item.players = players;
      console.log("item", item);
    });
    // load order with updated info, create registration, and skip pmt
    // this.adminService.LoadLostOrders(order).subscribe(data => {
    //   console.log(data);
    //   console.log('finished');
    // });
  });
  console.log("orderlist", orders);
// });}

我正在记录的数据很有趣。记录器首先返回的是每个项目,然后是订单列表,然后是更新的播放器信息。每个项目均显示列为ZoneAwarePromise的玩家数组。我不知道如何用实际数据替换它,但是我可以看到它没有按预期的顺序记录。

我如何才能获得带有更新数据的物品?

item logged, showing ZoneAwarePromise for player data updated info logged

1 个答案:

答案 0 :(得分:0)

从我了解到您正在尝试做的事情中,我想到了这一点,

~/.local/lib/python3.6/site-packages