Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在html表格中显示firebase中的数据_Javascript_Firebase_Firebase Realtime Database - Fatal编程技术网

Javascript 如何在html表格中显示firebase中的数据

Javascript 如何在html表格中显示firebase中的数据,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,我是新来的firebase,我已经创建了一个android应用程序,将数据存储到firebase,现在我正在开发一个web应用程序,可以在html表格中显示这些数据,但我真的不知道怎么做。 这是我的html代码: <center> <table style="width:80%"> <tr id="tr"> <th>Registracija vozila:</th> <th>Status vozila:&

我是新来的
firebase
,我已经创建了一个android应用程序,将数据存储到firebase,现在我正在开发一个web应用程序,可以在html表格中显示这些数据,但我真的不知道怎么做。 这是我的html代码:

<center>
<table style="width:80%">
  <tr id="tr">
    <th>Registracija vozila:</th>
    <th>Status vozila:</th> 

  <tr> 
  </tr>
  <tr>
    <tr>
  </tr>
</table>
</center>

<script>
    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.registracija + '</td>';
                content += '<td>' + val.status + '</td>';
                content += '</tr>';
            });
            $('#ex-table').append(content);
        }
    });
</script>

登记处:
沃兹拉州:
var database=firebase.database();
database.ref()一次('value',函数(快照){
if(snapshot.exists()){
var内容=“”;
snapshot.forEach(函数(数据){
var val=data.val();
内容+='';
content+=''+val.registicija+'';
内容+=''+val.status+'';
内容+='';
});
$('#ex table')。追加(内容);
}
});

您可以做的是创建一个简单的isFirst boolean,并且随着forEach按顺序运行(我假设您的列标题是第一个返回的内容),那么您所需要的就是这样的内容:

您可以向我们展示一些您尝试用于连接数据库的代码吗?如果不是的话,我们没有太多的事情来帮助你。尝试浏览firebase文档,并尽可能深入了解。Stack Overflow不是教程网站。要了解如何使用Firebase填充网页,我建议web开发人员从或开始。@CalebAnthony我更新了my code您的HTML没有id为
ex table
的元素,因此这不起作用:
$('#ex table')
。您可能正在查找
$('table')。追加(内容)@FrankvanPuffelen i更改了元素的名称,但仍然没有显示任何数据
snapshot.forEach(function(child) {
    if(isFirst){
        createHeaders(child.val());
        isFirst = false; //So it only will run once.
    }

    showItems(child.val(), child.key);
});