這裏是我的JSON和Code,它只給出數組,但不給它賦值。正如我曾經推動它產生的獨特ID,我沒有得到。所有存儲在該ID中的值。如何使用JavaScript爲每個對象檢索firebase JSON中的數據
{
"nitin" : [ {
"mobile" : {
"-K7GalDi5aAahDENCRi" : {
"name" : "file:///D:/Software%20Drive/addItem.html?category=mobile",
"price" : 345,
"quantity" : 34
}
},
"perfume" : {
"-K7K7HSu4rQNwbH3ud0H" : {
"name" : file:///D:/Software%20Drive/addItem.html?category=perfume",
"price" : 1000,
"quantity" : 20
}
}
}]
}
這是我的代碼時,子節點,你查詢的位置下添加直接
fbref.on("value", function(snapshot) {
var newPost = snapshot.val();
console.log(newPost);
fbref.on("child_added", function(newPost,pre){
newchild=newPost.val();
console.log(newchild);
var n=newPost.key();
console.log("this is key"+n);
console.log("Name"+newchild.name);
console.log("Price"+newchild.price);
console.log("Quantity"+newchild.quantity);
});
});
這有幫助嗎? https://jsfiddle.net/ab11b7h6/ – Amir