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

时间:2017-09-15 20:01:33

标签: angularjs arrays json slice

目前我有非常大的JSON数据,我想在使用JSON数据在Angular JS Controller中处理之前制作修剪版本。

在下面的JSON数据中,我不想拥有htmlComment[ { "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 } ] 元素,如何在处理数据之前删除它们并拥有新的非常轻的版本JSON数据

这里为了简单起见我已经制作了非常简单的JSON数组,但实际上我的数据非常接近100mb。

我已经解决了很多仍无法解决的问题

  1. Ref 1
  2. Ref 2
  3. Ref 3
  4. 以下是JSON数据

     with dupe as ( 
       select id, 
         json_document->'Firstname'->0->'Content' as first_name, 
         json_document->'Lastname'->0->'Content' as last_name, 
         identifiers->'RecordID' as record_id 
       from 
         (select 
           *, 
           jsonb_array_elements(json_document->'Identifiers') as identifiers 
          from staging ) sub 
          group by
            id,
            record_id, 
            json_document 
          order by last_name ) 
     select * from dupe da 
       where exists 
         (select * 
           from dupe db 
           where 
             db.record_id = da.record_id 
             and db.id != da.id
         )
    

1 个答案:

答案 0 :(得分:1)

在每个数据阵列上使用地图:

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;
});

只有您在映射对象中包含的字段才会填充新数据集。