gpt4 book ai didi

javascript - 如何查看表中的 firebase 对象

转载 作者:行者123 更新时间:2023-12-03 00:39:37 28 4
gpt4 key购买 nike

我有一个 firebase 医生表,我想在 html 表格中显示它。我已经在控制台中做到了这一点,但无法在 html 中显示它。我尝试使用 createElement() 但它显示错误。我的代码如下

var ref=database.ref('doctors');
ref.on('value',getData, errData);

function getData(data){
//console.log(data.val());
var doctors=data.val();
var keys=Object.keys(doctors);
console.log(keys);

for (var i = 0; i < keys.length; i++) {
var k=keys[i];
var designation=doctors[k].designation;
var doctor_email=doctors[k].doctor_email;
var doctor_id=doctors[k].doctor_id;
var doctor_phone=doctors[k].doctor_phone;
var hospital_id=doctors[k].hospital_id;
var isApproved=doctors[k].isApproved;
var name=doctors[k].name;
var specialization=doctors[k].specialization;
var token=doctors[k].token;

console.log(designation,doctor_email,doctor_id,doctor_phone,hospital_id,isApproved,name,specialization,token)
}
}

最佳答案

例如,只需添加一个带有 id div_output 的 div,然后使用它来构建表格,如下所示:

var output = document.getElementById("div_output");
output.innerHTML = "<table>"; // clearing any previous html content
// and setting up header row
output.innerHTML += "<tr>"
+ "<th> Designation </th>"
+ "<th> E-Mail </th>"
+ "<th> ID </th>"
+ "<th> Phone </th>"
+ "<th> Hospital ID </th>"
+ "<th> Approved? </th>"
+ "<th> Name </th>"
+ "<th> Specialization </th>"
+ "<th> Token </th>"
+ "</tr>";

for (var i = 0; i < keys.length; i++) {
var k=keys[i];
var designation=doctors[k].designation;
var doctor_email=doctors[k].doctor_email;
var doctor_id=doctors[k].doctor_id;
var doctor_phone=doctors[k].doctor_phone;
var hospital_id=doctors[k].hospital_id;
var isApproved=doctors[k].isApproved;
var name=doctors[k].name;
var specialization=doctors[k].specialization;
var token=doctors[k].token;
// appending doctor's row of data
output.innerHTML += "<tr>"
+ "<td>" + designation + "</td>"
+ "<td>" + doctor_email+ "</td>"
+ "<td>" + doctor_id+ "</td>"
+ "<td>" + doctor_phone+ "</td>"
+ "<td>" + hospital_id+ "</td>"
+ "<td>" + isApproved + "</td>"
+ "<td>" + name + "</td>"
+ "<td>" + specialization + "</td>"
+ "<td>" + token + "</td>"
+ "</tr>";

}

output.innerHTML += "</table>"; //closing the table

关于javascript - 如何查看表中的 firebase 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53513198/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com