我无法在我的 firestore 数据库中添加数据 请帮助我:(
React-Native 博览会
import React, { Component } from 'react';
import { StyleSheet, Text, View, TouchableOpacity,KeyboardAvoidingView,ToastAndroid , Alert} from 'react-native';
import { collection, addDoc , doc , getFirestore} from "firebase/firestore";
import { TextInput } from 'react-native-gesture-handler';
import {Header} from 'react-native-elements';
import db from '../config';
import Modal from 'react-native-modal';
const database = getFirestore()
const saveData = async() => {
const docRef = await addDoc(collection(database , "employee"),{
Name:this.Name,
SalaryPerHour:this.SalaryPerHour
});
console.log("DOcument ADD");
}
export default class AttendanceScreen extends Component {
state = {
visibleModal: null,
};
_renderButton = (text, onPress) => (
<TouchableOpacity onPress={onPress}>
<View style={styles.button}>
<Text>{text}</Text>
</View>
</TouchableOpacity>
);
_renderModalContent = () => (
<View style={styles.modalContent}>
<TextInput placeholder='Name'
maxLength={20}
onChangeText={(text)=>{
this.setState({
Name: text
})
}} />
<TextInput placeholder='Salary Per Hour'
maxLength={20}
keyboardType={'numeric'}
onChangeText={(text)=>{
this.setState({
SalaryPerHour: text
})
}} />
{/* {this._renderButton('Close', () => ths.setState({ visibleModal: null }))} */}
<TouchableOpacity onPress={()=>saveData()}>
<View style={styles.button}>
<Text>Save</Text>
</View>
</TouchableOpacity>
</View>
);
render() {
return (
<View style={styles.container}>
{this._renderButton('Add Employee', () =>
this.setState({ visibleModal: 4 })
)}
<Modal
isVisible={this.state.visibleModal === 4}
backdropColor={'aquamarine'}
backdropOpacity={1}
animationIn={'zoomInDown'}
animationOut={'zoomOutUp'}
animationInTiming={1000}
animationOutTiming={1000}
backdropTransitionInTiming={1000}
backdropTransitionOutTiming={1000}>
{this._renderModalContent()}
</Modal>
</View>
);
}
}`
我曾尝试寻找解决方案,但我什么也没找到。
我曾尝试从 firebase 文档基本添加到数据库。
Ì 试图创建功能,但这对我也不起作用。
我尝试了另一种方法,但它只适用于预定义值,但我希望它能处理用户输入的表单,但这对我不起作用。请有人帮助我。