Arrays 按日期对对象数组进行角度排序

Arrays 按日期对对象数组进行角度排序,arrays,angular,sorting,Arrays,Angular,Sorting,我知道有很多类似的话题,但我都试过了,都没用 我的脚本从不同的数据库中提取不同类型的活动,并为每个活动将id和日期添加到公共数组(activiteList) TS文件: _maj(id) { this.activiteList = []; this.csltList = []; this._getCslt(id); this.deplList = []; this._getDepl(id); console.log('Before sorti

我知道有很多类似的话题,但我都试过了,都没用

我的脚本从不同的数据库中提取不同类型的活动,并为每个活动将id和日期添加到公共数组(activiteList)

TS文件:

_maj(id) {
    this.activiteList = [];

    this.csltList = [];
    this._getCslt(id);

    this.deplList = [];
    this._getDepl(id);

    console.log('Before sorting', this.activiteList);

    this.activiteList.sort(function (a, b) {
      return a.date - b.date;
    });

    console.log('After sorting', this.activiteList);
  }

_getCslt(id) {
  if (isDefined(id) && id !== '') {
    this.csltService.getCslt(id).toPromise().then(cslts => {
      this.csltList = [];
      if (isDefined(cslts)) {
        cslts.forEach((cslt) => {
          const csltTr = new CsltModel(
            new Date(cslt.csltDateTime),
            cslt.author,
            cslt.motif,
            cslt.userId,
            id
          );
          csltTr.id = cslt.id;
          this.csltList.push(csltTr);

          this.activiteList.push({
            'date': new Date(cslt.csltDateTime).getTime(),
            'type': 'cslt',
            'id': cslt.id
          });
        });
      }
      this.cd.markForCheck();
    });
  }
}

_getDepl(id) {
  if (isDefined(id) && id !== '') {
    this.deplService.getDepl(id).toPromise().then(depls => {
      this.deplList = [];
      if (isDefined(depls)) {
        depls.forEach((depl) => {
          const deplTr = new DeplModel(
            new Date(depl.deplDateTime),
            depl.author,
            depl.conclusion,
            depl.missions,
            depl.userId,
            id
          );
          deplTr.id = depl.id;
          this.deplList.push(deplTr);

          this.activiteList.push({
            'date': new Date(depl.deplDateTime).getTime(),
            'type': 'depl',
            'id': depl.id
          });
        });
      }
      this.cd.markForCheck();
    });
  }
}
在_maj函数的末尾,我尝试按日期对activiteList数组进行排序,并将其存储为时间戳。我尝试了我发现的所有排序功能,排序前后的控制台警报保持不变

[]
0: {date: 1584625856088, type: "cslt", id: "0aeae480-109d-4329-9be5-ef4f8933d550"}
1: {date: 1581506529640, type: "depl", id: "ebfc3f2a-54db-41ba-b9a2-982b6c2d4756"}
2: {date: 1584625891099, type: "depl", id: "696b15df-8f7d-42d5-af52-ec03b171c837"}
length: 3
__proto__: Array(0)


提前谢谢你

谢谢你的回复。这是我在.ts文件的第12行中所做的,但要处理一个新变量。我只是试过,还是一样。。。
myList = [{date: 1584625856088, type: "cslt", id: "0aeae480-109d-4329-9be5-ef4f8933d550"},{date: 1581506529640, type: "depl", id: "ebfc3f2a-54db-41ba-b9a2-982b6c2d4756"},
{date: 1584625891099, type: "depl", id: "696b15df-8f7d-42d5-af52-ec03b171c837"}]
var sort = myList.sort(function(x, y){
    return y.date - x.date;
})
console.log(sort)