React-native:Firebase如何获取所有数据

Ama*_*oux 0 firebase react-native firebase-realtime-database

大家好我怎样才能从这种数据库结构中请求所有数据?

在此输入图像描述

我试过这个,但它不起作用:

 var recentPostsRef = firebase.database().ref('/store');
Run Code Online (Sandbox Code Playgroud)

Pat*_*ham 9

您处于正确的轨道上,但缺少.then()与回调一起使用的检索部分:

var recentPostsRef = firebase.database().ref('/store');
recentPostsRef.once('value').then(snapshot => {
  // snapshot.val() is the dictionary with all your keys/values from the '/store' path
  this.setState({ stores: snapshot.val() })
})
Run Code Online (Sandbox Code Playgroud)

firebase.database.Reference文档有很多很好的例子和解释可以提供帮助.