如何将此给定对象转换为另一个对象?

时间:2019-07-15 10:53:10

标签: javascript arrays ecmascript-6

我正在尝试将我从后端获取的对象转换为另一个对象,以便我可以轻松地映射它们,并将块和字段显示到前端。

我得到的对象是这样的:

{
  "success": true,
  "result": {
    "0": {
      "mapstructure": [
        [//This are the fields i will have to display to UI
          [
            "automatic_close",
            "casecreator"
          ],
          [
            "casesname",
            "case_no"
          ],
          [
            "casesolutiondealer"
          ]
        ]
      ],
      // This is the block name which will contain the fields given 
      above
      "blocks": [
        "LBL_CASES_INFORMATION"
      ]
    },
    "info": {
      //This are the values of all fields, but i want only the 
      //fields that i was given above
      "automatic_close": "0",
      "casecreator": "Dealer",
      "casesname": "adaptation from Italian to German PTB",
      "casesolutiondealer": "",
      "cases_no": "C201827417",
      "casetopn": "",
      "cbcaseassign": "19x82",
      "cf_1015": "waiting_for_an_answer",
      "cf_902": "Parts Support",
      "cf_903": "KIT Support"
    }
  }
}

我想转换成这样的对象

blocks: [
  [
  blockname:"LBL_CASES_INFORMATION".
  fields: {
    automatic_close: "0",
    casecreator:"xxxx",
    casesname: "SSSS",
    case_no: "tttt",
    casesolutiondealer:"tttt",
  }]
]

所以基本上我想在mapstructure数组中获取给我的字段的值,并像上面的对象一样组织它们,以便我可以更轻松地将它们呈现给UI。

如何使用.map,.filter和.reduce做到这一点?

0 个答案:

没有答案