好的。需要一些新鲜的眼睛来发现我的错误:
试图通过GraphQL从mongo数据库中获取JS Carousel的内容(由trapi生产)。
处理具有相关导入的组件:
import { Query } from 'react-apollo'
import { gql } from 'graphql-tag'
import React, { Component } from 'react'
import { Carousel, CarouselItem, CarouselControl, CarouselIndicators, CarouselCaption } from 'reactstrap'
在我班上
...snippet...
render() {
const GET_CAROUSELS = gql`
query carousels {
carousels {
_id
caption_header
caption_text
alt_text
slide_file { url }
}
}`
return (
<Query query={GET_CAROUSELS} errorPolicy="all">
{({ loading, error, data }) => {
let cars = data.carousels
if (error) console.log(error)
if (!cars || cars.length == 0){
return <div>No Carousels found</div>
} else {
return (
<React.Fragment>
<Carousel activeIndex={this.activeIndex}
next={this.next}
previous={this.previous} >
{cars.map(carousel => (
<CarouselItem key={carousel._id}>
<img scr={carousel.slide_file.url} />
</CarouselItem>
))}
</Carousel>
我尝试了许多排列,并且当前的代码错误与cannot read property of 'map' undefined
我的QLGraph游乐场显示此查询工作正常:
query {carousels {
_id
caption_header
caption_text
alt_text
slide_file { url }
}
}
我尝试更改<Query query
,但无济于事。尝试是否允许let cars = data.carousels
有时只是let cars=carousels
,等等。
救命,我的眼睛受伤了。