我已将firebase云存储中的读写规则设置为true,但是,当我尝试向数据库中添加多个文档时,firebase控制台中仅显示第一个文档。我正在React中设置一个变量作为对象,然后将该对象添加到数据库中。没有来自前端或后端的反馈。如何添加更多文档?
import React, { useState } from 'react';
import Table from './Table';
import firebase from '../firebase';
const Form = () => {
const[activity,setActivity]=useState({
date:"",
back:false,
chest:false,
biceps:false,
triceps:false,
forearms:false,
quads:false,
hams:false,
calves:false,
abs:false,
delts:false,
traps:false,
tread:false,
skip:"",
cigs:"",
com:""
});
const postValues = () => {
firebase
.firestore()
.collection("exercises")
.add({
activity
});
setActivity({});
};
//for checkbox values
const updateField = e => {
setActivity({
...activity,
[e.target.name]: e.target.checked
});
};
//For non checkbox values
const updateField2 = e => {
setActivity({
...activity,
[e.target.name]: e.target.value
});
};
return (
<div>
ADD YOUR WORKOUT
<form onSubmit={postValues}>
Date<input type="date" name="date" onChange={updateField2}/>
Back:<input type="checkbox" checked={activity.back} name="back" onChange={updateField}/>
Chest:<input type="checkbox" name="chest" onChange={updateField}/>
Biceps:<input type="checkbox" name="biceps" onChange={updateField}/>
Triceps:<input type="checkbox" name="triceps" onChange={updateField}/>
Forearms:<input type="checkbox" name="forearms" onChange={updateField}/>
Quads:<input type="checkbox" name="quads" onChange={updateField}/>
Hamstrings:<input type="checkbox" name="hams" onChange={updateField}/>
Calves:<input type="checkbox" name="calves" onChange={updateField}/>
Abs:<input type="checkbox" name="abs" onChange={updateField}/>
Deltoids:<input type="checkbox" name="delts" onChange={updateField}/>
Traps:<input type="checkbox" name="traps" onChange={updateField}/>
Treadmill:<select name="tread" onChange={updateField2}>
<option>0</option>
<option>5</option>
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
</select>
Skipping:<select name="skip" onChange={updateField2}>
<option>0</option>
<option>5</option>
<option>10</option>
<option>15</option>
<option>20</option>
<option>25</option>
</select>
Cigs:<select name="cigs" onChange={updateField2}>
<option>0</option>
<option>5</option>
<option>10</option>
<option>15</option>
<option>20</option>
<option>20+</option>
</select>
Comments:<textarea name="com" onChange={updateField2}></textarea>
<button>Add record</button>
</form>
<Table />
</div>
);
};
export default Form;