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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React-Table 不渲染數(shù)據(jù)

React-Table 不渲染數(shù)據(jù)

躍然一笑 2021-06-02 18:02:14
我正在嘗試在 react-table 組件中呈現(xiàn)一些數(shù)據(jù),但是數(shù)據(jù)沒有加載。我已經(jīng)用完全相同格式的虛擬數(shù)據(jù)進行了測試,它工作正常。但是,當我進行 API 調(diào)用并獲取相同格式的數(shù)據(jù)并將其推送到我傳遞給 react-table 的數(shù)據(jù)列表時,該表不會呈現(xiàn)它。請幫我找出問題所在。干杯設置列:    columns: [      {        Header: "Employee ID",        accessor: "EmployeeID"      },      {        Header: "First Name",        accessor: "FirstName"      },      {        Header: "Last Name",        accessor: "LastName"      },      {        Header: "Date of Birth",        accessor: "DateOfBirth",      },      {        Header: "Status",        accessor: "Status",      },      {        Header: "Gender",        accessor: "Gender",      },      {        Header: "UpdatedDateUTC",        accessor: "UpdatedDateUTC",      }    ]數(shù)據(jù)是什么樣的:{"EmployeeID":"63c571b3-bff0-4ce1-94f7-255c235580fa","FirstName":"Clive","LastName":"Thomas","Status":"ACTIVE","DateOfBirth":"/Date(697248000000+0000)/","Gender":"M","UpdatedDateUTC":"/Date(1533706298000+0000)/"}我的 API 調(diào)用以及我如何將數(shù)據(jù)項保存到狀態(tài)。(我控制臺記錄了我獲得的數(shù)據(jù)的值,并且格式正確)fetch('http://localhost:3100/employees')      .then((resp) => {        return resp.json()      })      .then((data) => {        let temp = this.state.posts;        temp.push(data.Employees[1])        this.setState({posts: temp})        console.log(this.state.posts)      })      .catch((error) => {        console.log(error, "catch the hoop")      })我還打印了成功插入列表的虛擬數(shù)據(jù)以及未插入的 API 數(shù)據(jù)。如您所見,它們顯然是相同的:
查看完整描述

2 回答

?
桃花長相依

TA貢獻1860條經(jīng)驗 獲得超8個贊

不確定這是否會解決您的問題,但 IMO 您應該將其重構為


fetch('http://localhost:3100/employees')

      .then((resp) => {

        return resp.json()

      })

      .then((data) => {

        let temp = [...this.state.posts]

        temp.push(data.Employees[1])

        this.setState({

            posts: temp,

            data: data

        })

        console.log(this.state.posts) //this will not have the newest values yet, setState is async

      })

      .catch((error) => {

        console.log(error, "catch the hoop")

      })

對反應狀態(tài)執(zhí)行操作不是一個好習慣


查看完整回答
反對 回復 2021-06-03
?
ABOUTYOU

TA貢獻1812條經(jīng)驗 獲得超5個贊

你為什么要推動員工[1]?那將是第二個記錄。


查看完整回答
反對 回復 2021-06-03
  • 2 回答
  • 0 關注
  • 548 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號