0

I tried to solve it like this: How to pull out data from firebase into html page - Stackoverflow

But I couldn't get it to work.

My html looks where I'll put the information from Firebase looks this in javascript:

var createTable = "<table><thead><tr id='keysRow'></tr></thead>";
var endHead = "<tbody><tr id='valuesRow'></tr></tbody></table>";  

//More code that's connecting to each other and displays it in a div.
//F12 is showing me that this works.

Firebase.js:

var firebase = require('firebase');
firebase.initializeApp(config);
var v = firebase.database();

var users = firebase.database().ref("users");


users.orderByKey().once('child_added', function(snapshot){
snapshot.forEach(function(childsnapshot){

var key = childsnapshot.key(); <---------error
var data = childsnapshot.val();

$('#keysRow').append('<th>' + key + '</th>');
$('#valuesRow').append('<td>' + data + '</td>');
});
});

config is just the link to the firebase. I have no problem using the config to write in the firebase.

The error is telling me: "childsnapshot.key is not a function"

Also my firebase has 10 different values I need to get.

Peter Haddad
  • 65,099
  • 21
  • 108
  • 107
LunaLuna
  • 61
  • 6

1 Answers1

1

Change this:

var key = childsnapshot.key();

to this:

var key = childsnapshot.key;

check this link to see what has changed in Firebase 3.x: https://firebase.google.com/support/guides/firebase-web

Peter Haddad
  • 65,099
  • 21
  • 108
  • 107
  • Thanks :D Next problem: $ is not defined ' + key + ''); – LunaLuna Feb 10 '18 at 16:58
  • that is another problem not related to this question, but you can check this to solve it https://stackoverflow.com/questions/2194992/jquery-is-not-defined . You may have your javascript file before the jquery script (check the link to solve it) – Peter Haddad Feb 10 '18 at 17:02