我在这里尝试做的实际上是从我的firestore中读取数据。我遵循了RNF文档中的所有安装,但当我尝试从我的文档中获取数据或者只是引用到firestore集合中时,出现了一个错误:

我试着改变规则(因为我认为这是涉及到的规则),但没有成功。下面是我的数据库结构:

下面是我的代码:
import React, { Component } from 'react';
import {View, Text, FlatList, Image, StyleSheet, Button, TouchableHighlight} from 'react-native';
import firebase from 'react-native-firebase';
import MainApp from './src/screen/test';
export default class App extends Component<{}> {
constructor(){
super();
this.itemsRef = this.getRef('questions');
this.state = {
items:[],
loading:true,
};
}
setModalVisible(visible){
this.setState(modalVisible:visible);
}
getRef(location){
return firebase.firestore().collection('chat');
}
componentWillMount(){
this.getItems(this.itemsRef);
}
componentDidMount(){
//this.getItems(this.itemsRef);
}
getItems(itemsRef){
firebase.firestore().collection('Users').get().then((snap)=>{
let items =[];
alert(snap);
snap.forEach((childSnap)=>{
items.push({
title:childSnap.val().question,
_key:childSnap.key
});
alert(childSnap.key)
})
this.setState({
items,
loading:false
})
})
}
pressRow(item){
alert(item);
}
renderRow(item){
return(
<TouchableHighLight onPress={()=>{
this.pressRow(item)
}}>
<View>
<Text>{item.title}</Text>
</View>
</TouchableHighLight>
)
}
addItem(){
}
render() {
if (this.state.loading) {
return null; // or render a loading icon
}
return (
<View style={{ flex: 1 }}>
<FlatList
data={this.state.items}
/>
<Button
title={'Add TODO'}
onPress={() => console.log()}
/>
</View>
);
}
}如何修复此错误?
发布于 2017-10-26 16:42:56
firestore的默认设置是禁用访问。
因此,如果您没有设置访问规则,则无法获取数据。
将它们更改为以下内容-但仅用于测试:
service cloud.firestore { match /databases/{database}/documents { // Match all documents, recursively, with a wildcard and the "=**" recursive modifier match /{document=**} { allow read, write; } } }
然后,在它工作之后-阅读更多关于here的内容。
https://stackoverflow.com/questions/46947671
复制相似问题