我想从Firebase实时数据库中检索数据,并使用用户注册后已经键入的数据库内部的数据自动填充它。我将用户数据保存在他们的UID下,现在我遇到了一个问题,无法通过用户UID从数据库中检索数据并通过当前登录用户uid自动为用户填充。

我的Firebase数据库
https://imgur.com/a/BlzFADs

自动填充的地方
https://imgur.com/a/urvNAFe

我为我的代码尝试了所有可能的解决方案,但是我似乎无法使其正常工作,我在stackoverflow上找到的所有解决方案,但仍然对我不起作用。

我的JS文件

 firebase.database().ref('Users/User Information').child(uid).once('value',
 function(snapshot) {

   document.getElementById('name').value = snapshot.child("Name").val();
 });


我的HTML档案

 <td>Name:</td>
 <td>
     <input type="text" id="name" name="name" style="font-size:10pt; width:200px;" placeholder="Enter Name Here" required>
 </td>


现在,我想根据他们的UID自动为当前登录用户填充数据。

最佳答案

试试下面的代码:

firebase.database().ref('Users/User Information/'+uid.value).once('value',
 function(snapshot) {
   document.getElementById('name').value = snapshot.val().Name;
});


或者使用箭头功能:

firebase.database().ref('Users/User Information/'+uid.value).once('value', (snapshot) =>
{
  document.getElementById('name').value = snapshot.val().Name;
});

关于javascript - 从Firebase实时数据库中检索数据并自动填充到文本框中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54301548/

10-10 17:07
查看更多