难以在innerHTML中显示数据

时间:2018-01-14 07:34:24

标签: javascript html firebase firebase-realtime-database

这是我加载表格的代码。使用的变量name和HTML中的表格id是正确的,file11用于innnerHTML,用于存储所有tdtr代码,并且没有存储来自firebase的数据,并且当在控制台中打印时,它没有显示任何内容。

PRINTSCREEN OF CONSOLE

function initializer(){
    refReview=firebase.database().ref().child("review");
    tableBody = document.getElementById("table_body");
    loadTables();   
}

function loadTables(){
    refReview.on("value", function(snap){
        var data = snap.val();
        var file11 = "";

        for(var key in data){
            console.log("keys retrieved",data[key].revieweeID);
            var idOfReviewee = data[key].revieweeID;

            getDataToUsers = firebase.database().ref("users").child(idOfReviewee);
            getDataToUsers.once("value",function(snap){
                var fnLn =snap.val();
                    console.log(fnLn.firstname);
                    file11 += "<tr>" +
                                    "<td>" + fnLn.firstname + "</td>" +
                                    "<td>" + fnLn.lastname + "</td>" +
                              "</tr>";
            });

            console.log("data of table file11:",file11);

        }//end of for loop

        tableBody.innerHTML = file11;

    });
}       //end table function

但如果这是代码的结构,file11innerHTML内部有数据,表格结构良好。但我想从firebase数据库中的其他组获取某个审阅者的数据。直到检索存储在不同组中的名称,并根据revieweeID进行引用。

function loadTables(){
    refReview.on("value", function(snap){
        var data = snap.val();
        var file11 = "";

        for(var key in data){
            console.log("keys retrieved",data[key].revieweeID);
            var idOfReviewee = data[key].revieweeID;

            getDataToUsers = firebase.database().ref("users").child(idOfReviewee);
            getDataToUsers.once("value",function(snap){
                var fnLn =snap.val();
                    console.log(fnLn.firstname);
            });

            file11 += "<tr>" +
                            "<td>" + data[key].content + "</td>" +
                            "<td>" + data[key].content + "</td>" +


                      "</tr>";

            console.log("data of table file11:",file11);

        }//end of for loop

        tableBody.innerHTML = file11;

    });
}       //end table function

0 个答案:

没有答案