我正在研究如何過濾Angular2中的數據數組。在angular2中過濾數組
我用自定義管道看了一下,但我覺得這不是我正在尋找的東西,因爲它似乎更適合於簡單的表示轉換,而不是過濾大量數據。
陣列被設置列如下:
getLogs(): Array<Logs> {
return [
{ id: '1', plate: 'plate1', time: 20 },
{ id: '1', plate: 'plate2', time: 30 },
{ id: '1', plate: 'plate3', time: 30 },
{ id: '2', plate: 'plate4', time: 30 },
{ id: '2', plate: 'plate5', time: 30 },
{ id: '2', plate: 'plate6', time: 30 }
];
}
我想通過id來過濾此。因此,當我在搜索欄中輸入「1」時,它會更新以顯示相應的值。
如果有如何做到這一點的方法,我很想知道!
PipeTransform的實現是做什麼的?我對它的目的有點困惑。 – Witted
事實上,當你想要實現一個管道時,你需要實現這個接口並把你的處理放在'transform'方法中。有關更多詳細信息,請參閱相應文檔:https://angular.io/docs/ts/latest/api/core/PipeTransform-interface.html。它的第一個參數對應於列表本身,第二個參數用於篩選列表中的元素... –
感謝您的解釋。最後一個問題是有可能將(ngf)的元素列表中的* ngFor =「#元素」作爲變量的輸出嗎? – Witted