Ionic 3,Firebase |从数据库中删除数据

时间:2019-01-30 21:05:43

标签: firebase ionic-framework firebase-realtime-database ionic3

我想从数据库中删除数据。我已经找到

的孩子的钥匙
firebase.database().ref('Applications/' + 
   this.IDofLibrary).orderByChild('IDofUser').equalTo(input.IDofUser)
      .once('value').then(snapshot => {
        snapshot.forEach(function(child) {
                console.log(child.key)
                this.keyy = child.key // This line gave error ------        
        });
    });

正如我所说,我已经在Google Chrome的控制台中看到了孩子的钥匙,如下图所示(图1)

Picture 1

-LXQwVU8EFarKEsdNQtq是我孩子的钥匙。

但是当我尝试将其保存到变量中时,出现了诸如top(图片1)图片之类的错误。

下面的所有代码。我怎样才能删除这个孩子?

  AcceptOrNot(input){
    this.once = true;
    const alert = this.alertCtrl.create({
      title: input.nameOfUser +' ' + input.lastnameOfUser + 'onaylansın mı?' ,

       buttons: [
        {
          text: 'Onayla',
          handler: data => {


            this.database.list('Applications/' + this.IDofLibrary + '/').valueChanges().subscribe((data2) => {
                for(let item2 of data2){
                    if(this.once == true){
                        console.log("Once bilgisi : " + this.once)
                        console.log(item2.IDofUser  +  " ----" + input.IDofUser)
                      if(item2.IDofUser == input.IDofUser){
                            firebase.database().ref('Applications/' + this.IDofLibrary).orderByChild('IDofUser').equalTo(input.IDofUser)
                                .once('value').then(snapshot => {
                                    snapshot.forEach(function(child) {
                                        if(child.exists){
                                            console.log(child.key);
                                            this.keyy = child.key.toString;
                                        }

                                    });
                                });

                        this.database.list('Applications/' + this.IDofLibrary + '/').push({
                            Email : item2.Email,
                            IDofUser : item2.IDofUser ,
                            nameOfUser : item2.nameOfUser,
                            lastnameOfUser : item2.lastnameOfUser,
                            whichLibrary : item2.whichLibrary,
                            dateOfBorn : item2.dateOfBorn,
                            canBeRezerve : 'true',

                        });
                        this.once = false;
                      }
                     item2 = {};
                    }
                }
  })
          }
        },
        {
          text: 'Reddet',
          handler: data => {
            console.log('Saved clicked');
          }
        }
      ]
    });
    alert.present();
  }

编辑:Informations of child

谢谢!

0 个答案:

没有答案