我有一个API,可以获取我的记录列表。我想显示按日期排序的那些记录。即最新记录将排在首位,也是明智之举。 我已经为此编写了一个打字稿代码,但是它似乎没有对我的行进行排序。 有人可以帮我做错什么吗?
this.recommendationService
.getJobExecutionStatList(project.id)
.subscribe(data => {
// this.jobExecutionList = data;
let data1:any = data;
this.jobExecutionList = new MatTableDataSource();
var sorrtedArray: Array<
any
> = data1.sort((n1, n2) => {
console.log(n1);
let date1 = new Date(n1.executionDate.replace('T','').replace(/-/g,'/'));
let date2 = new Date(n2.executionDate.replace('T','').replace(/-/g,'/'));
if (date1 > date2) {
return 1;
}
if (date1 < date2) {
return -1;
}
return 0;
});
// this.jobExecutionList = sorrtedArray;
console.log(sorrtedArray);
this.jobExecutionList.data = sorrtedArray;
this.jobExecutionList.sort = this.sort;
this.jobExecutionList.paginator = this.paginator;
});
}