简体   繁体   中英

How can we read multiple references nested while reading data from javascript firebase database?

How can we read multiple references nested while reading data from javascript firebase database?

var refEmanet = firebase.database().ref('emanet');
// Add ref of child if any
refEmanet.on('value', function(snapshot) {
    var icerik="" 
    var no=1;
    snapshot.forEach((child)=>{
        
        if(child.val().geriVermeTarihi!=0){
            dataArray[no]=child.val();
                  console.log(child.val().isbn);
        icerik+='<tr>';
            icerik+='<td>'+no+'</td>';
const dbRef2 = firebase.database().ref();
            dbRef2.child("kitaplar").child(child.val().kitapId).get().then((snapshot2) => {
                if (snapshot2.exists()) {
                    var no1=0;
                        if(snapshot2.key==child.val().kitapId){
                    console.log(snapshot2.val().kitapAdi);
                    icerik+='<td>'+snapshot2.val().kitapAdi+'</td>'; 
                    no1++;
                    }
                    
                    

                } else {
                    console.log("No data available");
                }
                }).catch((error) => {
                    console.error(error);
                });
           
            icerik+='<td>'+child.val().isbn+'</td>';

            const dbRef3 = firebase.database().ref();
            dbRef3.child("ogrenciler").child(child.val().ogrId).get().then((snapshot3) => {
                if (snapshot3.exists()) {
                    
                    console.log(snapshot3.val());
                    icerik+='<td>'+snapshot3.val().ad+' '+snapshot3.val().soyad+'</td>'; 
                    

                } else {
                    console.log("No data available");
                }
                }).catch((error) => {
                    console.error(error);
                });

//            icerik+='<td>'+child.val().ogrId+'</td>';
            icerik+='<td>'+child.val().emanetTarihi+'</td>';
            icerik+='</tr>';
            no++;  
        }


    });

   console.log(snapshot.val());
    $('#ex-table').append(icerik);


});

在此处输入图像描述

Can we not nest in firebase realtime database? I couldn't solve this. As you can see in the table, the data is not coming. But I can read data from logs. How do I solve this?

let myTable = document.getElementById('ex-table').getElementsByTagName('tbody')[0];

              let row = myTable.insertRow();
              let cell1=row.insertCell(0);
              let cell2=row.insertCell(1);
              let cell3=row.insertCell(2);
              let cell4=row.insertCell(3);
              let cell5=row.insertCell(4);
              let cell6=row.insertCell(5);
              let cell7=row.insertCell(6);
              let cell8=row.insertCell(7);
              let cell9=row.insertCell(8);
              cell1.innerHTML=no
              .
              .
              .

this is how i solved it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM