【发布时间】:2018-03-08 10:42:15
【问题描述】:
我创建了这个简单的函数(根据本指南:https://medium.com/@jamesmarino/getting-started-with-react-native-and-firebase-ab1f396db549)
export function getNameOfUserToKill(userID, gameID, callback) {
let path = '/games/' + gameID + '/' + userID;
fb
.database()
.ref(path)
.on('value', snapshot => {
var nameOfUserToKill = '';
if (snapshot.val()) {
nameOfUserToKill = snapshot.val().userToKill;
}
callback(nameOfUserToKill);
});
}
但我不知道如何最终获得数据......
我应该做nameOfUserToKill = getNameOfUserToKill(USER1234, GAME65754) 吗?我不知道“回调”是什么意思。感谢您的帮助。
所以我可以做到:
var nameOfUserToKill = '';
export function getNameOfUserToKill(userID, gameID) {
let path = '/games/' + gameID + '/' + userID;
fb
.database()
.ref(path)
.on('value', snapshot => {
nameOfUserToKill = '';
if (snapshot.val()) {
nameOfUserToKill = snapshot.val().userToKill;
}
});
}
var user = nameOfUserToKill;
【问题讨论】:
-
您不需要回调来检索数据,也请检查:codeburst.io/…
标签: javascript reactjs firebase react-native firebase-realtime-database