我正在嘗試在 Modal 部分打印 Selectedproduct 對象的屬性,并且在到達“描述”數組屬性之前一切正常,它顯示“無法讀取未定義的屬性‘map’”。盡管當我使用 console.log(Selectedproduct) 時 description 屬性正常出現,但是當我編寫 console.log(Selectedproduct.description) 我不知道為什么它認為它是未定義的。你能告訴我為什么它看不到描述為獨立財產?import React, { Component } from "react";import FormatCurrency from "../Components/util";import Slide from "react-reveal/Slide";import Modal from "react-modal";import Zoom from "react-reveal/Zoom";import { connect } from "react-redux";import { GetProducts } from "../Actions/ItemsActions";import { AddToCart } from "../Actions/CartActions";class Products extends Component { constructor(props) { super(); this.state = { show: false, Selectedproduct: {}, }; } showModal = (product) => { console.log(product); this.setState({ show: true, Selectedproduct: product }); }; hideModal = () => { this.setState({ show: false }); }; componentDidMount() { this.props.GetProducts(); } render() { const { Selectedproduct } = this.state; return ( <div> <Slide left cascade={true}> {!this.props.products ? ( <div> Loading..</div> ) : ( <ul className="products"> {this.props.products.map((product) => ( <li key={product._id}> <div className="product"> <a href={"#" + product._id}> <img src={product.image} alt={product.title} onClick={() => this.showModal(product)} ></img> <p>{product.title}</p> </a> <div className="product-price"> <div> {FormatCurrency(product.price)}</div>
我正在嘗試使用 map 函數在對象內部打印數組,但我得到:無法讀取未定義的屬性映射
泛舟湖上清波郎朗
2023-05-25 17:35:51