【问题标题】:filtering data from firebase-realtime-database从 firebase-realtime-database 过滤数据
【发布时间】:2019-04-10 01:02:27
【问题描述】:

我正在尝试从具有用户用户名值的 firebase 获取数据。一周前我尝试了 2 种不同的方法,但现在我又回来了,我注意到我已经删除了它。

在 home.ts 中我订阅数据的地方

this.database.list<EventModels>('event-list').valueChanges().subscribe((eventData) => { 

}, (err)=>{
 console.log("Error while retrieving event details : ", err);
}); 

this.eventListRef$ = this.database.list<EventModels>('event-list');
this.eventList$ = this.eventListRef$.snapshotChanges()
.pipe(
  map(changes => 
    changes.map(c => ({ id: c.payload.key, ...c.payload.val() }))
  )
);

我要过滤的数据等于creator

由于我将创建者设置为用户的电子邮件,我想列出所有仅由用户创建的事件,使用 == firebase.auth().currentUser.email 并且我尝试过的所有事件都失败了。

【问题讨论】:

    标签: typescript ionic-framework firebase-realtime-database angularfire2


    【解决方案1】:

    来自AngularFire documentation on querying lists

    db.list('/items', ref => ref.orderByChild('size').equalTo('large'))
    

    所以看起来你的应该是这样的:

    this.eventListRef$ = this.database.list<EventModels>('event-list', 
      ref => firebase.database().ref("event-list").orderByChild("email").equalTo(firebase.auth().currentUser.email));
    

    【讨论】:

      猜你喜欢
      • 2020-07-26
      • 1970-01-01
      • 2022-12-01
      • 2020-12-04
      • 1970-01-01
      • 2019-11-14
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      相关资源
      最近更新 更多