firebase嵌套对象返回null-javascript

firebase嵌套对象返回null-javascript,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,我想得到嵌套的子对象,就像在图像中一样,但它返回null。我想要价格和数量的值,并在表中显示它们 检查此数据库映像 代码 你指向了错误的路径,这就是为什么你得到空值。以下是Firebase文档所说的: 如果没有数据,则返回的快照为空 我无法从图像中看到整个数据库结构,但请尝试再次检查路径,以下是我的最佳猜测: var foodItems = firebase.database().ref(`Orders/'${listid}/foodItems`) foodItems.on('value',

我想得到嵌套的子对象,就像在图像中一样,但它返回null。我想要价格和数量的值,并在表中显示它们

检查此数据库映像

代码


你指向了错误的路径,这就是为什么你得到空值。以下是Firebase文档所说的:

如果没有数据,则返回的快照为空

我无法从图像中看到整个数据库结构,但请尝试再次检查路径,以下是我的最佳猜测:

var foodItems = firebase.database().ref(`Orders/'${listid}/foodItems`)
foodItems.on('value', snapshot => {
   // the snapshot should return the foodItems array
   snapshot.forEach((obj) => {
          console.log(obj.price)
          console.log(obj.quantity)
   })

})

如果您的
listid
是和exist键,那么您错误地键入了路径:
fooditems
,请尝试此操作

var countRef = firebase.database().ref('Orders/' + listid);
countRef.on('value', snapshot => {
if (snapshot.exists()) {
   var b = snapshot.child("fooditems/price").val();
   var c = snapshot.child("fooditems/quantity").val();
    console.log(c);
}
});

你能告诉我怎么收拾桌子吗?我正在使用“材质”对话框和“材质表”。当点击按钮时,它会显示包含able的对话框,但每次点击按钮时,它都会在上一个按钮的下方添加新数据。@Ganesh用完整的代码发布另一个问题,以便我能帮助您。在这里检查
var countRef = firebase.database().ref('Orders/' + listid);
countRef.on('value', snapshot => {
if (snapshot.exists()) {
   var b = snapshot.child("fooditems/price").val();
   var c = snapshot.child("fooditems/quantity").val();
    console.log(c);
}
});