我在Angular web應用中使用AngularFire2。由於Firebase的查詢限制,我無法形成完全提供我需要的數據的查詢(至少不會對我的模式進行重大更改)。如何在客戶端過濾FirebaseListObservable?
所以我想在javascript(typescript)中應用額外的客戶端過濾條件。我該怎麼做呢?我可以以某種方式添加一個過濾器函數給observable?下面是一個說明我在做什麼的片段。
在組件的HTML模板中,我有下面這樣的東西。 html片段中的「jobs」變量是FirebaseListObservable。
<tr *ngFor="let job of jobs | async">
.. fill in the table rows
分量代碼看起來是這樣的:
// in the member declaration of the class
jobs : FirebaseListObservable<Job[]>;
...
// Notice in ngOnInit(), I'm filtering the jobs list using the the
// Firebase criteria. But I want to filter on an additional field.
// Firebase allows only single field criteria, so I'm looking for
// a way to apply an additional client-side filter to jobs to eliminate
// some additional records.
ngOnInit(){
this.jobs = this.af.database.list("/jobs/", {query: {orderByChild : "companyKey", equalTo:someKey}})
}
是否有適用於「this.jobs」這樣我就可以申請本地(客戶端)過濾器過濾器部件的方法嗎?
是的,你是對的。我修正了我的例子。謝謝你的出色答案。 –