我试着这样解决: How to pull out data from firebase into html page - Stackoverflow
但我无法让它发挥作用。
我的html看起来我将来自Firebase的信息放在javascript中查看:
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>');
});
});
Firebase.js:
function listClients() {
var sender = getCookieData('relay_client_id');
if (sender) {
socket.emit('list_relay_clients', sender, (callback) => {
return callback; //This won't work because it's async
});
return callback; //<---- I need it to be here
}
}
config只是firebase的链接。我使用配置在firebase中写入没有问题。
错误告诉我:&#34; childsnapshot.key不是函数&#34;
此外,我的firebase还有10个不同的值。
答案 0 :(得分:1)
改变这个:
var key = childsnapshot.key();
到此:
var key = childsnapshot.key;
点击此链接,查看Firebase 3.x中的更改内容:https://firebase.google.com/support/guides/firebase-web