我有一個 React 組件,它接收數據,通過它進行映射并打印出包含通過的對象中的數據的引導卡。但是我有一個問題,即返回的數據不允許我調用.map(報告錯誤TypeError: this.props.data.map is not a function),即使我認為console.log數據似乎是一個數組。我的代碼如下,console.log 中顯示的數據也是如此。我讀過關于 SO 的其他問題,一般答案似乎是數據不是數組——但我的似乎是。我已經嘗試將數據轉換為數組const data = Array.from(this.props.data);然后<CardDeck>{data.map(renderCard)}</CardDeck>這讓我更進一步,但后來我得到TypeError: Cannot read property '$numberDouble' of undefined與數據區域相關的錯誤,例如 "manufacturer": "Panini","number": { "$numberDouble": "16"},誰能建議我在這里做錯了什么?我從 props 獲取數據,而不是從 state - 見下圖我還可以通過以下方式將數據打印到屏幕上return ( <Container> <h1>Hello {JSON.stringify(this.props.data)}</h1> {/* <CardDeck>{this.props.data.map(renderCard)}</CardDeck> */} {/* <CardDeck>{data.map(renderCard)}</CardDeck> */} </Container> );
× TypeError: this.props.data.map 不是函數
忽然笑
2023-04-27 16:17:17