使用 papaparse 遍历特定数据后如何解析结果?

How to unparse result after iterating through specific data with papaparse?

我正在尝试使用 PapaParse 解析本地 CSV 文件并遍历 JSON 以便仅从文件输出特定数据。

示例:我只希望第 "Mill Description" 列匹配 adidas && Champion,所有其他数据都将被丢弃。

如果您需要更多说明,请随时询问,我会定期查看。

CSV 文件:https://ufile.io/ze7xl

papa.parse(file, {
  worker: true,
  header: true,
  transformHeader: true,
  step: function(result) {
    var data = result.data;
    for (var i = 0; i < data.length; i++) {
      var millDescription = JSON.stringify(data[i]["Mill Description"]);
      if (
        millDescription.includes("adidas") ||
        millDescription.includes("Champion")
      ) {
      // This is where I need help
      }
    }
  },
  complete: function(result, csv) {
    console.log("parsing complete read: ", result, csv); // Nothing is passed to here yet.
  }
});

试试这个

 papa.parse(file, {
  worker: true,
  header: true,
  transformHeader: true,
  step: function(result) {
    let data = result.data;
    data = data.filter(d => d["Mill Description"].includes('adidas') || d["Mill Description"].includes('adidaChampions'));
  },
  complete: function(result, csv) {
    console.log("parsing complete read: ", result, csv); // Nothing is passed to here yet.
  }
});

输出看起来像这样,多个 JSON 数组,然后我的问题是如何解析所有数据以转换回 csv 文件?

[{
      "Item Number": "B12704533",
      "GTIN Number": "190311332942",
      "Mill Code": "04",
      "Mill Description": "adidas Golf",
      "Style Number": "A262",
      "Mill Style Number": "TWA262S8",
      "Style Name": "AD LADS MICRO STRIPE POLO",
      "Color Code": "53",
      "Color Description": "ROYAL",
      "Size Code": "3",
      "Size Description": "S",
      "Unit Weight": ".7258",
      "Cost": "0",
      "CC": "0",
      "CD": "0",
      "FO": "0",
      "KC": "0",
      "MA": "0",
      "PH": "0",
      "TD": "0",
      "CN": "0",
      "WA": "0",
      "GD": "316",
      "Total Inventory": "316"
    }]
    [{
      "Item Number": "B12704534",
      "GTIN Number": "190311332966",
      "Mill Code": "04",
      "Mill Description": "adidas Golf",
      "Style Number": "A262",
      "Mill Style Number": "TWA262S8",
      "Style Name": "AD LADS MICRO STRIPE POLO",
      "Color Code": "53",
      "Color Description": "ROYAL",
      "Size Code": "4",
      "Size Description": "M",
      "Unit Weight": ".7717",
      "Cost": "0",
      "CC": "0",
      "CD": "0",
      "FO": "0",
      "KC": "0",
      "MA": "0",
      "PH": "0",
      "TD": "1",
      "CN": "0",
      "WA": "0",
      "GD": "540",
      "Total Inventory": "541"
    }]