我尝试了以下代码:
return firebase.database().ref('/pastrls/-M1akNXVk6VhnykRc-zN').once('code').then(function(snapshot) {
var code = (snapshot.val() && snapshot.val().username) || 'Anonymous';
document.write(code);
});
答案 0 :(得分:0)
更改此:
return firebase.database().ref('/pastrls/-M1akNXVk6VhnykRc-zN').once('code').then(function(snapshot) {
var code = (snapshot.val() && snapshot.val().username) || 'Anonymous';
document.write(code);
});
对此:
return firebase.database().ref('/pastrls/-M1akNXVk6VhnykRc-zN').once('value').then(function(snapshot) {
var code = snapshot.val().code;
document.write(code);
});
首先添加对节点-M1akNXVk6VhnykRc-zN
的引用,然后使用once()
,它将从数据库中检索数据。然后在回调函数中使用snapshot.val().code
来获取code
属性。