我可以将数据添加到Firebase上的Firestore中。但是我无法从中获取数据。
有人可以给我榜样和良好的配置吗?
错误:
无法调用RNFirebaseFirestore.collection获取空
Image for error when try to get data
Build.gradle on Project
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com'
}
}
}
在应用程序上构建.gradle
dependencies {
implementation(project(':react-native-firebase')){
transitive = false
}
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:23.0.1"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.firebase:firebase-firestore:15.0.0"
}
apply plugin: 'com.google.gms.google-services'
我使用的版本:
"dependencies": {
"firebase": "^5.3.0",
"react-native": "0.55.4",
"react-native-firebase": "^4.3.8",
这是我获取数据的代码
firebase.firestore().collection("Product").get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
});
预先感谢
答案 0 :(得分:-1)
尝试以下代码:-
this.dbRef = firebase.database().ref("Product");
this.dbRef.once(
"value",
snapshot => {
console.log(snapshot.key, "Response: " + snapshot.val());
},
errorObject => {
console.log("The read failed: " + errorObject.code);
}
);