Javascript 如何使用Firebase在Ionic 3中通过参数检索数据

Javascript 如何使用Firebase在Ionic 3中通过参数检索数据,javascript,angular,firebase,firebase-realtime-database,ionic3,Javascript,Angular,Firebase,Firebase Realtime Database,Ionic3,我在Firebase上有一个实时数据库,我想使用参数从该数据库检索记录 例如,在您看到的层次结构中,我希望使用uID值获取数据。我该怎么做 更新 我在我给出的链接上尝试了文章中的标题“ReadFirebase Data”,但如果代码是为Ionic 2编写的,我不知道如何更新代码 这是我写的代码 import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ioni

我在Firebase上有一个实时数据库,我想使用参数从该数据库检索记录

例如,在您看到的层次结构中,我希望使用uID值获取数据。我该怎么做

更新

我在我给出的链接上尝试了文章中的标题“ReadFirebase Data”,但如果代码是为Ionic 2编写的,我不知道如何更新代码

这是我写的代码

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Post } from '../../models/models/post';
import { AngularFireDatabase } from 'angularfire2/database';
import { Storage } from '@ionic/storage';

@IonicPage()
@Component({
  selector: 'page-profile',
  templateUrl: 'profile.html',
})

export class ProfilePage {

  public posts: Post[];
  public uID: string;

  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    private db: AngularFireDatabase,
    private storage: Storage) {

    this.storage.get('uID').then((val) => {
      console.log('uID: ' + val);
      this.uID = val;
      console.log('this.uID: ' + this.uID);

      this.db.list<Post>('/Post/',
        ref => ref.orderByChild('uID').equalTo(this.uID)).valueChanges().subscribe(t => {
          this.posts = t;
        })
    });

  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ProfilePage');
  }

}
和产出

Try Val: function () {
        util_1.validateArgCount('DataSnapshot.val', 0, 0, arguments.length);
        return this.node_.val();
    }
Try Key: User
Try Child: function (childPathString) {
        util_1.validateArgCount('DataSnapshot.child', 0, 1, arguments.length);
        // Ensure the childPath is a string (can be a number)
        childPathString = String(childPathString);
        validation_1.validatePathString('DataSnapshot.child', 1, childPathString, false);
        var childPath = new Path_1.Path(childPathString);
        var childRef = this.ref_.child(childPath);
        return new DataSnapshot(this.node_.getChild(childPath), childRef, PriorityIndex_1.PRIORITY_INDEX);
    }
更新

我可以得到数据,但答案不清楚

Firebase使用键值记录所有数据。我还在“/Post/”值之后添加了这个键值作为数据路径。例如“/Post/-1ersksnu0nsw1/”

这是代码

 db.database.ref('/User/-L88gtymS5pS3KWtZrmI').on('value', res => {
      console.log(res.val().email)
    });
我可以得到真实的值,但我仍然不知道如何根据他们记录的列来做这件事。

你可以检查这个。它创建了一个聊天应用程序,但它可能会帮助你做你想做的事情

firebase.database().ref('/Post/').on('value', resp => {
    console.log(resp)
});
尤里卡

db.database.ref('/User/').orderByChild('uID').equalTo(this.uID).once('value', (snapshot) => {
   console.log(snapshot.val().email)
})

这段代码可以做到这一点。

到目前为止你尝试了什么?@RadonirinaMaminiaina我实际上什么都没试过,因为虽然很容易被列出,但我找不到关于这个主题的任何明确信息@RadonirinaMaminiaina感谢您的回复,我尝试了“读取Firebase数据”主题,但它在带有AngularFire的Ionic 3上抛出语法错误。我会用这个更新问题。@RadonirinaMaminiaina谢谢你的回答,我更新了postHi,但我不能使用“firebase.database().ref…”,我在构造函数中注入了AngularFirebaseDatabase变量,它没有像你这样使用的变量。
db.database.ref('/User/').orderByChild('uID').equalTo(this.uID).once('value', (snapshot) => {
   console.log(snapshot.val().email)
})