[英]Display nested data from Firebase in html using javascript?
please help me with my code.请帮我处理我的代码。 I tried display retrieved data in my html table using javascript, but nothing work.
我尝试使用 javascript 在我的 html 表中显示检索到的数据,但没有任何效果。 I am new in firebase, if it possible please anyone help me or give advice, I have already tried everything methods on stack (
我是 firebase 的新手,如果可能请任何人帮助我或提供建议,我已经尝试了堆栈上的所有方法(
The structure of my base looks like this,please check the image from the link below我的基地结构是这样的,请查看下面链接中的图片
/Notes/{Generated User Token}/{Generated Date}/{Generated Note ID}/Fields /Notes/{Generated User Token}/{Generated Date}/{Generated Note ID}/Fields
My Html Code我的 Html 代码
<table style="width:100%" id="ex-table">
<tr id="tr">
<th>Name:</th>
</table>
Javascript 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);
}
});
I do not know how to write a path to Generated Date " DateddMMyyyy " and Generated Note ID " NoteXXXXXXX "我不知道如何编写生成日期“ DateddMMyyyy ”和生成注释 ID “ NoteXXXXXXX ”的路径
I need only display end fields from structure.
我只需要显示结构中的结束字段。 What should I edit in my code?
我应该在我的代码中编辑什么?
Ps: For more details about Generated date, please check code from android studio " timeStamp = new SimpleDateFormat("ddMMyyyy").format(Calendar.getInstance().getTime());
" Ps:有关生成日期的更多详细信息,请查看 android 工作室的代码“
timeStamp = new SimpleDateFormat("ddMMyyyy").format(Calendar.getInstance().getTime());
"
For getting the date formated id pass the input date to getDateId
use it to construct the database.ref()
要获取日期格式的 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.