我必須通過不同的欄位對來自服務器的資料進行動態排序。它與除時隙欄位外的所有欄位完美配合。我必須按時隙欄位按升序對資料進行排序,問題是時隙是字串,例如:“09:00-09:59”。
我的排序功能是:
function sortArray(array: any[], direction: string, extractor: (any) => any): any[] {
return array.sort((e1, e2) =>
(direction === 'asc' && extractor(e1) > extractor(e2)) || (direction !== 'asc' && extractor(e1) < extractor(e2))
? 1
: -1
);
}
我該如何解決?如果有人知道,請告訴我。謝謝你。
uj5u.com熱心網友回復:
你的sortArray函式很好。您必須檢查 sort.active 和 sort.direction 是否正確更新。
試試這樣:
console.log('this.sort.active', this.sort.active);
console.log('this.sort.direction', this.sort.direction);
如果他們沒有更新,那么這就是問題所在。然后修改你更新這些東西的邏輯。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/464709.html
標籤:javascript 有角度的 打字稿
上一篇:在Angular中使用API時使用{returnthis.getAll.get(this.url)}遇到一些問題
