[英]How do I fetch the value from a key in firebase using javascript
var dbImages = firebase.database().ref("images");
dbImages.on("value", function(images){
if(images.exists()){
var imageshtml = "";
images.forEach(function(fetchImages){
console.log("key: " + fetchImages.key);
console.log("title: " + fetchImages.title);
console.log("url: " + fetchImages.url);
});
}
});
Its only showing key value not other value i want to view key value and also the value of key value please help guys它只显示键值而不显示其他值我想查看键值以及键值的值请大家帮忙
You are using forEach()
and DataSnapshot
of /orders
node where each child node seems to be a category and not the image itself.您正在使用/orders
节点的forEach()
和DataSnapshot
,其中每个子节点似乎是一个类别而不是图像本身。 You'll have to loop over each image of the categories to list them:您必须遍历类别的每个图像才能列出它们:
firebase.database().ref("images").once("value").then((imagesCategories) => {
if (imagesCategories.exists()) {
var imageshtml = "";
// For each category
imagesCategories.forEach(function(categoryImages) {
// For each category image
categoryImages.forEach(function(image) {
// Append data to imageshtml from here
console.log(image.val().url)
console.log(image.val().title)
})
})
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.