【问题标题】:How to view name and score on HTML from Firebase with Javascript如何使用 Javascript 从 Firebase 中查看 HTML 上的名称和分数
【发布时间】:2019-03-18 16:02:36
【问题描述】:

如何以表格格式查看 HTML 中的这些数据?

【问题讨论】:

    标签: javascript html firebase firebase-realtime-database


    【解决方案1】:

    试试这个,

    html

    <html>
    <body>
    <div class="dataFetch">
           <table border="1" id="fetch">
              <tr>
                 <th>Name</td>
                 <th>Value</td>
               </tr>
           </table>
         </div>
    
      <script>
       // Initialize Firebase...
    
      </script>
       <script src="customer.js"></script>
    
    </body>
    </html>
    

    js

    var table = document.getElementById('fetch');
    
    var rowIndex = 1;
    //var user_name = document.getElementById('user_name')
    function serch(){
    
    
    var data = firebase.database().ref('Users').child("Customers");
      data.once('value',function(snapshot){
        snapshot.forEach(function(childSnapshot){
          var childKey = childSnapshot.key;
          var childData = childSnapshot.val();
    
          var row = table.insertRow(rowIndex);
          var cellId = row.insertCell(0);
          var cellName = row.insertCell(1);
    
          cellId.appendChild(document.createTextNode(childKey));
          cellName.appendChild(document.createTextNode(childData));
    
          rowIndex = rowIndex + 1;
    
        });
    });
    }
    

    希望对你有帮助。

    【讨论】:

    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 2012-03-22
    • 2018-07-09
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多