Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 始终偶然发现此错误无法读取属性';地图';未定义的_Jquery_Reactjs - Fatal编程技术网

Jquery 始终偶然发现此错误无法读取属性';地图';未定义的

Jquery 始终偶然发现此错误无法读取属性';地图';未定义的,jquery,reactjs,Jquery,Reactjs,我目前正在做我的一个个人项目,并且总是偶然发现这个错误 //无法读取未定义的属性“map” 从'react bootstrap'导入{Container,Row,Col} 从“./CategoryListItem”导入CategoryListItem 从“react”导入{useContext} 从“/../Context/ApplicationContext”导入{ApplicationContext} 导出默认函数CategoryList(){ 让{products}=useContext(

我目前正在做我的一个个人项目,并且总是偶然发现这个错误

//无法读取未定义的属性“map”

从'react bootstrap'导入{Container,Row,Col}
从“./CategoryListItem”导入CategoryListItem
从“react”导入{useContext}
从“/../Context/ApplicationContext”导入{ApplicationContext}
导出默认函数CategoryList(){
让{products}=useContext(ApplicationContext)
让categoryDisplay=products.map(product=>{
返回(
)
})
返回(
{类别显示}
)
}

确保产品是一个阵列

import { Container, Row, Col } from 'react-bootstrap' 
import CategoryListItem from './CategoryListItem' 
import { useContext } from 'react' 
import { ApplicationContext } from './../contexts/ApplicationContext'


export default function CategoryList(){

let { products} = useContext(ApplicationContext)

let categoryDisplay = products? products.map( product =>{
    return(
        <Col xs={12} sm={6} md={4} lg={3} key={product._id}>
            <CategoryListItem product={product}/>
        </Col>
    )
}):" "


return(
    <Container className="my-5">
        <Row>
            {categoryDisplay}
        </Row>
    </Container>
)
}
从'react bootstrap'导入{Container,Row,Col}
从“./CategoryListItem”导入CategoryListItem
从“react”导入{useContext}
从“/../Context/ApplicationContext”导入{ApplicationContext}
导出默认函数CategoryList(){
让{products}=useContext(ApplicationContext)
让categoryDisplay=products?products.map(product=>{
返回(
)
}):" "
返回(
{类别显示}
)
}

在映射之前也要做一个检查,以防它为空,你可以控制产品。看看你得到了什么。看起来像是空的为什么有这么多标签<代码>属性指的是对象的属性
map
是一个特定属性,通常在数组中可用。显然,
products
不是一个数组,而是一个未定义的数组。你认为这个错误是什么意思?请拿着这本书读一读。请防止标签垃圾邮件。这被认为是粗鲁的。(我不知道标签和你的问题有什么关系。)对于标签,很抱歉,只是系统不允许我在不放置至少5个不同标签的情况下发布此内容,谢谢你的回复。
import { Container, Row, Col } from 'react-bootstrap' 
import CategoryListItem from './CategoryListItem' 
import { useContext } from 'react' 
import { ApplicationContext } from './../contexts/ApplicationContext'


export default function CategoryList(){

let { products} = useContext(ApplicationContext)

let categoryDisplay = products? products.map( product =>{
    return(
        <Col xs={12} sm={6} md={4} lg={3} key={product._id}>
            <CategoryListItem product={product}/>
        </Col>
    )
}):" "


return(
    <Container className="my-5">
        <Row>
            {categoryDisplay}
        </Row>
    </Container>
)
}