查询后 FirebaseListObservable 变为 Observable [英] FirebaseListObservable becomes Observable after query
问题描述
我在 firebase 上做了一个小应用.我一直在使用 angularfire 提供的一种称为 FirebaseListObservable 的类型,它允许您观察数据的变化.我遇到的问题是 Angularfire 还提供了一种查询数据的方法,方法是将查询对象附加/传递到请求中.
I made a small app on firebase. I have been using a type provided by angularfire called a FirebaseListObservable which allows you to observe changes to your data. The problem I'm having is that Angularfire also provides a way to query the data, by attaching / passing in a query object to the request.
以下返回一个 FirebaseListObservable.
The following returns a FirebaseListObservable.
this.resources$ = <FirebaseListObservable<IResource[]>> this.af.list(`/resources/${this.auth.id}`) as FirebaseListObservable<IResource[]>;
//这将返回一个常规的 observable.
//This returns a regular observable.
this.resources$ = <FirebaseListObservable<IResource[]>> this.af.list(`/resources/${this.auth.id}`,
{
query: {
orderByChild: `${property}`
}
}
) as FirebaseListObservable<IResource[]>;
但这会返回一个普通的旧 observable.问题是我需要一个 FirebaseListObservable,因为它添加了 CRUD 功能,我正在尝试编写简单的过滤器/排序方法.
But this returns a plain old observable. The issue is that I need a FirebaseListObservable because it has added CRUD functionality and I'm trying to write simple filter / sorting methods.
我可以看到他们有一个未解决的问题,但我希望迟早有办法解决这个问题.工单中讨论的解决方案描述了扩展 FirebaseListObservable 并覆盖提升方法以返回自定义 observable.我试图创建一个 CustomFirebaseListObservable 来做到这一点,但我似乎无法访问正确的属性(来自我的自定义 observable 中的 observable.source 和 observable.operator.我希望有一种方法可以将 observable 投射到一个 firebaseListObservable.任何解决方法都可以.
I can see they have an Open Issue for this but I'm hoping that there is a way around this issue sooner rather than later. The solution discussed in the ticket describes extending the FirebaseListObservable and overriding the lift method to return the custom observable. I attempted to create a CustomFirebaseListObservable that does just that, but I don't seem to have access to the correct properties (observable.source and observable.operator from within my custom observable. I'm hoping for a way to cast an observable to a firebaseListObservable. Any workaround would do really.
推荐答案
如果您仍然遇到此问题,也许您可以使用排序创建 firebase 引用,然后将其传递给 angularfire?
If you are still having this issue, maybe you can create the firebase reference with the ordering and then passing that into angularfire?
let refPath = `/resources/${this.auth.id}`,
ref = firebase.database().ref(refPath).orderByChild(property);
this.resources$ = <FirebaseListObservable<IResource[]>>this.af.list(ref);
这篇关于查询后 FirebaseListObservable 变为 Observable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!