【发布时间】:2021-02-21 17:44:44
【问题描述】:
但是当我通过 react js 实现这个例子时,我不能这样做。查看我的代码:
constructor(props) {
super(props);
this.ref = firebase.firestore().collection('stack_over')
const id = firebase.firestore().collection('stack_over').doc().id
this.state = {
question_id: id,
question_title: '',
};
}
onSubmitData = (e) => {
e.preventDefault()
const { question_id, question_title } = this.state;
this.ref.add({ question_id, question_title })
.then((docRef) => {
this.setState({ question_id:'', question_title:'' }) }).catch((error) => { console.error("", error) }) }
我想在插入新数据然后自动生成的文档 id 插入 question_id 字段时执行此操作。我该怎么做?
【问题讨论】:
标签: javascript reactjs firebase google-cloud-firestore