但在html页面中显示为未定义

但在html页面中显示为未定义

本文介绍了来自Firebase的数据在浏览器中显示正常,但在html页面中显示为未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从firebase DB下载的数据,并且数据很好,但是当将此数据加载到HTML中时,所有表TD都显示为未定义,无法理解为什么检查了很多代码而无法理解这里出了什么问题.

I have data downloaded from firebase DB and the data is fine but when this data is loaded into HTML all table TD shows undefined, not able to understand why been check a whole lot of codes not able to understand whats wrong here.

谢谢

var registration = firebase.database().ref("REGISTRATION")

dataRef = firebase.database().ref().child("REGISTRATION");

dataRef.on("value", rData);

function rData(data){

    console.log(data.val());
    var gData = data.val();
        for (gDatarow in gData)
    {
    alert(email);
        var email = gDatarow.email;
        var name = gDatarow.name;
        var gender = gDatarow.gender;
        var date = gDatarow.date;
        var phone = gDatarow.phone;
        var state = gDatarow.state;
        var school = gDatarow.school;
        var clas = gDatarow.clas;
        var classname = gDatarow.classname;
        $("#reData").append("<tr><td>" + email + "</td></td>" + name + "</td><td>" + gender + "</td></td>" + date + "</td><td>" + phone + "</td></td>" + state + "</td><td>" + school + "</td></td>" + clas + "</td><td>" + classname + "</td></tr>");

}
}

在此处输入图片描述

推荐答案

在我的情况下,这是有效的方法:

This is what worked in my case :

dataRef.on("child_added", function(data) {
    var rData = data.val();
$("#reData").append("<tr><td>" + rData.email + "</td><td>" + rData.name + "</td><td>" + rData.gender + "</td><td>" + rData.birthdate + "</td><td>" + rData.phone + "</td><td>" + rData.state + "</td><td>" + rData.school + "</td><td>" + rData.class + "</td><td>" + rData.classname + "</td></tr>");
});

感谢所有人的时间.

这篇关于来自Firebase的数据在浏览器中显示正常,但在html页面中显示为未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:39