[英]How to retrieve a value in Realtime Database using Javascript?
I don´t have a lot of programming experience, and I´m trying to solve the following: Given this data structure using Realtime Database Data Structure I want to show in an HTML table the value of the "propina"
key, but not the identifier that the Realtime Database generates.我没有很多编程经验,我正在尝试解决以下问题:鉴于此数据结构使用实时数据库数据结构,我想在 HTML 表中显示
"propina"
键的值,而不是实时数据库生成的标识符。
Up until now, I´m running this code to retrieve the values of the data:到目前为止,我一直在运行这段代码来检索数据的值:
` `
var database = firebase.database();
database.ref().once('value', function(snapshot){
if(snapshot.exists()){
var content = '';
snapshot.forEach(function(data){
var val = data.val();
content +='<tr>';
content += '<td>' + val.nombre + '</td>';
content += '<td>' + val.lugar + '</td>';
content += '<td>' + val.ubicacion + '</td>';
content += '<td>' + val.propina + '</td>';
content += '</tr>';
});
$('#ex-table').append(content);
}
});`
But the " propina"
value is not displayed, giving me just \[object Object\]
in the HTML.但是没有显示“
propina"
值,只给我 HTML 中的\[object Object\]
。
The issue is that propina
is an object , not a string or a number .问题是
propina
是object ,而不是字符串或数字。 You need to access its value .您需要访问它的值。 You can access the value like this:
您可以像这样访问值:
...
content += '<td>' + val.propina.value + '</td>';
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.