【发布时间】:2017-04-09 19:44:51
【问题描述】:
如何在 TypeScript 中对对象数组进行排序?
具体来说,根据一个特定属性对数组对象进行排序,在本例中为nome(“姓名”)或cognome(“姓氏”)?
/* Object Class*/
export class Test{
nome:String;
cognome:String;
}
/* Generic Component.ts*/
tests:Test[];
test1:Test;
test2:Test;
this.test1.nome='Andrea';
this.test2.nome='Marizo';
this.test1.cognome='Rossi';
this.test2.cognome='Verdi';
this.tests.push(this.test2);
this.tests.push(this.test1);
谢谢!
【问题讨论】:
-
你试过什么?请显示您尝试过的代码,我们可以建议如何修复它。
标签: angular sorting typescript