【发布时间】:2018-10-18 00:25:40
【问题描述】:
如何显示当前数据而不是获取多个数据。
我想删除以前的数据,因为每当新数据存储在 Firebase 上时,它都会复制大约 4 次相同的数据。
我正在使用移动应用向 Firebase 发送数据。我已将 databaseref.once 更改为 databaseref.on,因此它可以是一个实时数据库,但我的表上存储了多个数据。
<html>
<head>
<title>Firebase Realtime Database Web</title>
<script>
// firebase config here
</script>
</head>
<body>
<h3>Police Station 1</h3>
<table id="reports" border="1">
<tr>
<th>Email Address</th>
<th>Caption</th>
<th>Location</th>
<th>Time</th>
<th>Picture</th>
</tr>
</table>
<script>
var tblUsers = document.getElementById('reports');
var databaseRef = firebase.database().ref('PP3/');
var rowIndex = 1;
databaseRef.on('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
var row = tblUsers.insertRow(rowIndex);
var email = row.insertCell(0);
var caption = row.insertCell(1);
var location = row.insertCell(2);
var time = row.insertCell(3);
var picture = row.insertCell(4);
email.appendChild(document.createTextNode(childData.Email.replace(/\\/g, '').replace(/"/g, '')));
caption.appendChild(document.createTextNode(childData.Caption.replace(/\\/g, '').replace(/"/g, '')));
location.appendChild(document.createTextNode(childData.Location.replace(/\\/g, '').replace(/"/g, '')));
time.appendChild(document.createTextNode(childData.Time.replace(/\\/g, '').replace(/"/g, '')));
picture.appendChild(document.createTextNode(childData.Picture.replace(/\\/g, '').replace(/"/g, '')));
rowIndex = rowIndex + 1;
});
});
</script>
</body>
</html>
【问题讨论】:
标签: javascript html firebase firebase-realtime-database