【发布时间】:2016-04-10 15:29:54
【问题描述】:
这是我的 JSON 和代码,它只提供数组但不提供值。因为我使用 push 它从中生成唯一 ID,但我没有得到。存储在该 id 中的所有值。
{
"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);
});
});
【问题讨论】:
-
这有帮助吗? jsfiddle.net/ab11b7h6
标签: javascript json firebase firebase-realtime-database