微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ReactJS Firebase添加多个文档失败

如何解决ReactJS Firebase添加多个文档失败

我已将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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。