繁体   English   中英

使用 javascript 在 html 中显示来自 Firebase 的嵌套数据?

[英]Display nested data from Firebase in html using javascript?

请帮我处理我的代码。 我尝试使用 javascript 在我的 html 表中显示检索到的数据,但没有任何效果。 我是 firebase 的新手,如果可能请任何人帮助我或提供建议,我已经尝试了堆栈上的所有方法(

我的基地结构是这样的,请查看下面链接中的图片

/Notes/{Generated User Token}/{Generated Date}/{Generated Note ID}/Fields

我的 Html 代码

<table style="width:100%" id="ex-table">
  <tr id="tr">
    <th>Name:</th>
 </table>

Javascript

var database = firebase.database();
    var uid = firebase.auth().uid; // Not working, How to get a path to Generated tokens? 
    var date = // How to get a path to "DateddMMyyyy" from a structure?
    var notes = // How to get a path to "NoteXXXXXXX" from a structure?

    database.ref().child('Notes' +token+ '/' +date+ '/' +notes+ '/' ).once('value').then(function(snapshot) {
        if(snapshot.exists()){
            var content = '';
            snapshot.forEach(function(data){
                var val = data.val();
                content +='<tr>';
               content += '<td>' + val.name + '</td>';
                content += '</tr>';
            });
            $('#ex-table').append(content);
        }
    });

我不知道如何编写生成日期DateddMMyyyy ”和生成注释 IDNoteXXXXXXX ”的路径

我只需要显示结构中的结束字段。 我应该在我的代码中编辑什么?

Ps:有关生成日期的更多详细信息,请查看 android 工作室的代码“ timeStamp = new SimpleDateFormat("ddMMyyyy").format(Calendar.getInstance().getTime()); "

要获取日期格式的 id,请将输入日期传递给getDateId使用它来构造database.ref()

 function getDateId(dt){ var date = new Date(dt); var currentMonth = date.getMonth(); var currentDate = date.getDate(); if (currentMonth < 10) { currentMonth = '0' + currentMonth}; if (currentDate < 10) { currentMonth = '0' + currentDate}; return `Date${currentDate}${currentMonth}${date.getFullYear()}` } var inputDate = new Date(); var dateId = getDateId(inputDate); console.log(dateId)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM