第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

無(wú)法將來(lái)自 firebase 的提取數(shù)據(jù)顯示在 reactjs webapp 中

無(wú)法將來(lái)自 firebase 的提取數(shù)據(jù)顯示在 reactjs webapp 中

桃花長(zhǎng)相依 2022-09-02 21:07:43
import React, { Component } from 'react'import * as ReactBootStrap from 'react-bootstrap'import { Table } from 'react-bootstrap'import firebase from '../fire'import '../App.css'import Foot from './Foot'class Appointment extends Component {  state = {    data: []  }  componentDidMount() {    firebase.database().ref("appoinment").once("value").then(snapShot => {      snapShot.forEach(item => {        this.state.data.push({          id: item.key,          name: item.val().name,          age: item.val().age,          gender: item.val().gender,          Description: item.val().Description,          date: item.val().Appointdate        });      })    })  }  render() {    return (      <div className='cardback'>        <div>          <br></br>          {console.log(this.state)}          <br></br>          <h2 style={{ textAlign: 'center', fontSize: '30px' }}>Today's Appointment</h2>          <br></br>          <br></br>          <Table striped bordered hover variant="dark" style={{ width: "1200px", margin: 'auto' }}>            <thead>              <tr>                <td>id</td>                <td>name</td>                <td>age</td>                <td>gender</td>                <td>Description</td>                <td>date</td>                <td>Status</td>              </tr>            </thead>            <tbody>              **{                this.state.data.map((item) =>                  <tr>                    <td>{item.id}</td>                    <td>{item.name}</td>                    <td>{item.age}</td>                    <td>{item.gender}</td>                    <td>{item.Description}</td>                    <td></td>                  </tr>                )              }**                        </tbody>          </Table>          <br></br>          <br></br>        </div>        <Foot></Foot>      </div>    )  }}export default Appointment;這是上面的代碼我想從 firebase 獲取數(shù)據(jù)到 react-js 應(yīng)用程序。我能夠在控制臺(tái)上獲取整個(gè)數(shù)據(jù),但無(wú)法將其迭代為表形式。如下所示。在其中,我從firebase獲取數(shù)據(jù)并將其推送到數(shù)組中。所以基本上數(shù)據(jù)是一個(gè)對(duì)象數(shù)組。但我無(wú)法迭代我
查看完整描述

1 回答

?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

您正在直接改變狀態(tài),這不會(huì)導(dǎo)致任何重新渲染。不要做this.state.data.push({id:item.key,


Use this.setState


componentDidMount() {

  firebase

    .database()

    .ref("appoinment")

    .once("value")

    .then((snapShot) => {

      let updatedData = [];

      snapShot.forEach((item) => {

        updatedData.push({

          id: item.key,

          name: item.val().name,

          age: item.val().age,

          gender: item.val().gender,

          Description: item.val().Description,

          date: item.val().Appointdate,

        });

      });

      this.setState({ data: updatedData });

    });

}


查看完整回答
反對(duì) 回復(fù) 2022-09-02
  • 1 回答
  • 0 關(guān)注
  • 82 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)