【问题标题】:Ionic Sort multi dimension array离子排序多维数组
【发布时间】:2019-05-04 00:03:57
【问题描述】:

我有一个二维数组,我想按某个值排序,这是我的数组:

[
  [
    {
      "Categorie": "Alimentation",
      "Label": "Trsttzp",
      "Prix": "45",
      "Date": "01/12/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "Trst",
      "Prix": "65",
      "Date": "01/13/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "Ts",
      "Prix": "99",
      "Date": "01/02/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "Ts",
      "Prix": "99",
      "Date": "01/12/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "Haa",
      "Prix": "55",
      "Date": "01/12/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "qsd",
      "Prix": "6",
      "Date": "01/12/2018"
    }
  ]
]

我想按日期对其进行排序,我尝试使用 npm 中的“快速排序”库,但它似乎不起作用,我认为问题是这个库不适用于二维数组,我不能找到一种方法来使用打字稿或支持二维数组的库:x

【问题讨论】:

    标签: arrays typescript sorting ionic-framework


    【解决方案1】:

    很简单,只需这样做,无需 3rd 方库

    let arraysorted = array.sort((x,y) => new Date(x[0].Date) > new Date(y[0].Date));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      相关资源
      最近更新 更多