【问题标题】:retrieve the contents of the firebase database检索 firebase 数据库的内容
【发布时间】: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;

【问题讨论】:

标签: javascript reactjs firebase react-native firebase-realtime-database


【解决方案1】:

要检索 Firebase 数据库的内容:

 let path = '/games/' + gameID + '/' + userID;
fb.database().ref(path).on('value', snapshot => {
  var nameOfUserToKill = '';
  if (snapshot.val()) {
    nameOfUserToKill = snapshot.val().userToKill;
  }

nameofUserToKill 将包含检索到的数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多