Angularjs 如何在Angular JS中删除大型Json数组中的Json对象

Angularjs 如何在Angular JS中删除大型Json数组中的Json对象,angularjs,arrays,json,slice,Angularjs,Arrays,Json,Slice,目前,我有非常大的JSON数据,我想在使用JSON数据在Angular JS Controller中处理之前,制作一个精简版本 在下面的JSON数据中,我不想有comment和htmlComment元素,我如何在处理数据之前删除它们并获得新的非常轻版本的JSON数据 为了简单起见,我制作了一个非常简单的JSON数组,但实际上我有非常多的数据,几乎是100mb 我已经问了很多问题,但仍然不能回答 下面是JSON数据 [ { "executions": [ {

目前,我有非常大的JSON数据,我想在使用JSON数据在Angular JS Controller中处理之前,制作一个精简版本

在下面的JSON数据中,我不想有comment和htmlComment元素,我如何在处理数据之前删除它们并获得新的非常轻版本的JSON数据

为了简单起见,我制作了一个非常简单的JSON数组,但实际上我有非常多的数据,几乎是100mb

我已经问了很多问题,但仍然不能回答

下面是JSON数据

[
  {
    "executions": [
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      }
    ],
    "currentlySelectedExecutionId": "",
    "recordsCount": 210,
    "stepDefectCount": 0,
    "totalDefectCount": 0
  },
  {
    "executions": [
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      }
    ],
    "currentlySelectedExecutionId": "",
    "recordsCount": 210,
    "stepDefectCount": 0,
    "totalDefectCount": 0
  },
  {
    "executions": [
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      }
    ],
    "currentlySelectedExecutionId": "",
    "recordsCount": 210,
    "stepDefectCount": 0,
    "totalDefectCount": 0
  }
]

在每个数据数组上使用映射:

var lightData = rawData.map(function(item) { 
  // use Object.assign to prevent mutating original object
  var newItem = Object.assign({}, item);
  var lightExecutions = item.executions.map(function(d) {
    var ld = {
      id: d.id,
      orderId: d.orderId,
      executionStatus: d.executionStatus,
      executedOn: d.executedOn,
      executedBy: d.executedBy,
      executedByDisplay: d.executedByDisplay,
    };
    return ld;
  });
  newItem.executions = lightExecutions;
  return newItem;
});
只有映射对象中包含的字段才会填充新数据集。

添加了object.assign以防止原始数据发生突变。