【发布时间】:2019-03-18 16:02:36
【问题描述】:
如何以表格格式查看 HTML 中的这些数据?
【问题讨论】:
标签: javascript html firebase firebase-realtime-database
如何以表格格式查看 HTML 中的这些数据?
【问题讨论】:
标签: javascript html firebase firebase-realtime-database
试试这个,
<html>
<body>
<div class="dataFetch">
<table border="1" id="fetch">
<tr>
<th>Name</td>
<th>Value</td>
</tr>
</table>
</div>
<script>
// Initialize Firebase...
</script>
<script src="customer.js"></script>
</body>
</html>
var table = document.getElementById('fetch');
var rowIndex = 1;
//var user_name = document.getElementById('user_name')
function serch(){
var data = firebase.database().ref('Users').child("Customers");
data.once('value',function(snapshot){
snapshot.forEach(function(childSnapshot){
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
var row = table.insertRow(rowIndex);
var cellId = row.insertCell(0);
var cellName = row.insertCell(1);
cellId.appendChild(document.createTextNode(childKey));
cellName.appendChild(document.createTextNode(childData));
rowIndex = rowIndex + 1;
});
});
}
希望对你有帮助。
【讨论】: