查询后FirebaseListObservable变为可观察 [英] FirebaseListObservable becomes Observable after query

查看:216
本文介绍了查询后FirebaseListObservable变为可观察的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在firebase上做了一个小应用程序。我一直在使用由angularfire提供的名为FirebaseListObservable的类型,它允许您观察对数据的更改。我遇到的问题是,Angularfire还提供了一种查询数据的方式,通过附加/传递查询对象到请求。



以下内容返回FirebaseListObservable。

  this.resources $ = < FirebaseListObservable<的IResource [] GT;> this.af.list(`/ resources / $ {this.auth.id}`)作为FirebaseListObservable< IResource []>; 

//这将返回一个常规的可观察值。

  this.resources $ =< FirebaseListObservable< IResource []>> this.af.list(`/ resources / $ {this.auth.id}`,
{
query:{
orderByChild:`$ {property}`
}
}
)as FirebaseListObservable< IResource []>;

但是这会返回一个普通的旧观察值。问题是我需要一个FirebaseListObservable,因为它已经添加了CRUD功能,我正在尝试编写简单的过滤/排序方法。

我可以看到他们有一个 Open Issue ,但是我希望能早日解决这个问题, 。在故障单中讨论的解决方案描述了扩展FirebaseListObservable并重写lift方法以返回自定义observable。我试图创建一个CustomFirebaseListObservable这样做,但我似乎没有访问正确的属性(observable.source和observable.operator从我的自定义observable。我希望有一种方法来将一个可观察的如果你仍然有这个问题,也许你可以创建一个firebase的参考,你可以创建一个firebaseListObservable。任何解决方法将真正做到。

解决方案

订单,然后将它传递到angularfire?

$ $ $ $ $ $ $ $让refPath =`/ resources / $ {this.auth.id}`, $ ref $ firebase.database ref(refPath).orderByChild(property);
this.resources $ =< FirebaseListObservable< IResource []>> this.af.list(ref) ;


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.

The following returns a FirebaseListObservable.

this.resources$ = <FirebaseListObservable<IResource[]>> this.af.list(`/resources/${this.auth.id}`) as FirebaseListObservable<IResource[]>;

//This returns a regular observable.

this.resources$ = <FirebaseListObservable<IResource[]>> this.af.list(`/resources/${this.auth.id}`,
  {
    query: {
      orderByChild: `${property}`
    }
  }
) as FirebaseListObservable<IResource[]>;

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.

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.

解决方案

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变为可观察的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆