我试图从我导入的 js 文件中映射两个数组之一ProductInformation.js。
这是在我的主要组件类中<ProductSquare arrayId = {door}/>
我也尝试过<ProductSquare arrayId = {['door']}/>
我想要做的只是映射与panelIdprop 变量匹配的数组(两者中的)。
我得到一个错误 TypeError: Cannot read property 'map' of undefined
export const door = [
{
id: 1,
productSquareId: 'door',
productImage: require('./door.png'),
companyImage: require('./logo.png'),
price: '$55.99',
},
{
id: 2,
productSquareId: 'door',
productImage: require('./door.png'),
companyImage: require('./logo.png'),
price: '$55.99',
},
]
export const lighting = [
{
id: 1,
productSquareId: 'lighting',
productImage: require('./lighting.png'),
companyImage: require('./logo.png'),
price: '$55.99',
}
import React, { Component } from 'react';
import './ProductSquare.css';
import './grid-container.css'
import {door, lighting} from './ProductInformation.js';
class ProductSquare extends Component {
constructor(props)
{
super(props)
this.state = {
};
}
PopulateProductSquares()
{
const ProductSquares = this.props.arrayId.map((product, i) =>
<div className = "ProductSquare">
<img className = "MainImage" src ={this.props.arrayId[i].productImage} alt = "test"/>
<img className = "CompanyImage" src ={this.props.arrayId[i].companyImage} alt = "test"/>
<button className = "AddButton">
Add
</button>
<button className = "InfoButton">
Info
</button>
</div>
)
return (
ProductSquares
)
}
render() {
return (
this.PopulateProductSquares()
)
}
}
export default ProductSquare;