New to javascript here. I'm trying to pull a specific set of data from my firebase database and print it to my website but I am struggling to do so. The problem is it prints out every field in the database.
As you can see in this image, I would like the fields for just that particular ID printed out onto my website and not the fields for all the different ID's [1]: https://i.stack.imgur.com/FIOcO.png
Here is what I have so far
var db = firebase.firestore();
const list_div = document.querySelector("#list_div");
db.collection("catalogue").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
list_div.innerHTML += "<h3>" + doc.data().Name + "</h3><p> Price: " + doc.data().Price + "</p></div> Quantity" + doc.data().Quantity + doc.data().Description
});
});
The below will get data for id which you want:
function getDataById(anyId) {
db.collection("catalogue").doc(anyId).get()
.then(function(doc) {
if (doc.exits) {
var desc = doc.data().Description,
var name = doc.data().Name,
var price = doc.data().Price
var qty = doc.data().Quantity
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.