如何在TypeScript中對一組對象進行排序?對打字稿中的對象數組進行排序?
具體來說,對一個特定屬性(本例中爲nome
(「name」)或cognome
(「surname」))排列數組對象?
/* 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);
thx!
你試過了什麼?請顯示您嘗試過的代碼,並且我們可以建議如何解決它。 – RJM