2017-01-18 2 views
-1

JavaScriptでGoogle Firebaseを使用してテーブルを作成していますが、テーブルを表示していません。ここでFirebaseのダイナミックテーブルからウェブサイト用のJavaScriptを使用

は私のコードです:

<a href="#usertable" onclick="openLink(event,'usertable');tab1();" class="tablink w3-padding w3-hover-white" style="margin-top: 2px;font-size: 15px;">User Table</a> <!--function called on click on tab link--> 


       <table id="userTableInside" class="w3-table w3-centered w3-striped w3-card-2"> 
        <tr style="background: #cccccc;"> 
         <th>Institute Name</th> 
         <th>Role id</th> 
         <th>Institute id</th> 
         <th>Strikes</th> 
         <th>Status</th> 

         <!--<th>Perfomance Rating</th>--> 
        </tr> 
        <tr id="mytr"> 

        </tr> 

       </table> 

は、あなたがテーブルに

$( "#userTableInside> TBODYを" データを追加する必要が

<script> 

//initialized firebase also 
function tab1() { 
    var table= document.getElementById("userTableInside"); 
    var i = 1; 
    var institudeId = sessionStorage.getItem("InstituteId"); 
    var roleId = sessionStorage.getItem("RoleId"); 
    var ref_1 = firebase.database.ref(institudeId + "/Admin/Usertable/"); 
    ref_1.once('value', function(snapshot) { 
     snapshot.forEach(function(childSnapshot) { 

      var row= table.insertRows(i); 
      var x= row.insertCell(0); 
      var x1= row.insertCell(1); 
      var x2= row.insertCell(2); 
      x.innerHTML = childData.status; 
      x1.innerHTML = childData.totalTimeUsed; 
      x2.innerHTML = childData.report; 
      i++; 
      // ... 
     }); 
    }); 
</script> 
+0

'var childData = childSnapshot.val();' – cartant

答えて

-1

すべてがsnapshot.forEach除いて、私には罰金です。 snapshotの値を使用する前に、まずsnapshot.val()を使用してスナップショットから値を抽出します。

snapshot.val().forEachを使用してください。これがあなたの問題を解決することを願っています。

注: listenerイベントの時データベースの指定された場所にあるデータを含むスナップショットを受信します。 val()メソッドを使用してスナップショット内のデータをretrieveにすることができます。

スナップショットが直接使用されていることがわかったので、テーブル挿入ロジックをチェックしませんでした。

-1

上記のsrcスクリプトタグを追加しました).append( "+ col 1のデータ" + "col 2のデータ+" "+ col 3のデータ+" ");

"col 1のデータ"の代わりに適切な変数を使用してください。 テーブル行の最後を示すために、aで終わることを確認してください。

あなたの「子供」スルーあなたループするたびにこれを行います - 基本的には同じ場所であなたのコードを置き換える

関連する問題