我正在使用Firebase实时数据库和jquery进行项目。我必须从两个不同的节点检索数据并将其存储在数据表中。第一个查询返回值,并基于该值,我必须从另一个节点检索值。现在的问题是它返回的值很好,但是返回重复的值。
这是我的代码:
var database = firebase.database();
var userRef = database.ref("Users");
var orderRef = database.ref("Orders");
userRef.on("value", function(snapshot) {
snapshot.forEach(function(childSnapshot) {
userType = childSnapshot.val().UserType;
if (userType === 'r') {
restId = childSnapshot.key;
displayName = childSnapshot.val().DisplayName;
location = childSnapshot.val().Location;
orderRef.on("value", function(oSnapshot) {
oSnapshot.forEach(function(oChildSnapshot) {
location2 = oChildSnapshot.val().pickupLocation;
if (location === location2) {
deliveryLocation = oChildSnapshot.val().deliveryLocation;
driver = oChildSnapshot.val().driver;
status = oChildSnapshot.val().status;
completionTime = oChildSnapshot.val().timeOfCompletion;
pickupTime = oChildSnapshot.val().timeOfPickup;
date = oChildSnapshot.val().date;
table.row.add([restId, displayName, deliveryLocation, driver, status, completionTime, pickupTime, date]).node().id = "restId";
table.draw(false);
}
});
});
}
});
});