[英]Reactjs: Why is the Carousel not showing at all?
Ok so, I have this carousel. 好吧,我有这个旋转木马。 I am using AliceCarousel and I think that the logic is right because it filters just the ones with the
collection_name === "images"
我正在使用AliceCarousel ,我认为逻辑是正确的,因为它只过滤那些具有
collection_name === "images"
but it doesn't seem to be getting rendered. 但它似乎没有被渲染。 I am not receiving any errors so why?
我没有收到任何错误,为什么? this is the JSON structure,
这是JSON结构,
in case that I have forgotten something.
万一我忘记了一些东西。 I am trying to get all the image URLs and make it into a carousel.
我正在尝试获取所有图像URL,并将其放入轮播中。 please help me, I am new to Reactjs.
请帮助我,我是Reactjs的新手。
galleryItems() {
return (
this.state.brands.map((brand, i) => {
var checkImage = brand.media.length === 0 ? [] : brand.media.filter((media) => media.collection_name === "images");
console.log('henlos',checkImage)
checkImage.map((image, i) => (
<div key={`key-${i}`} className="card-img-top"><img src={image.url} /></div>
));
})
)
};
render(){
const items = this.galleryItems();
const responsive = {
0: { items: 2 },
600: { items: 2 },
1024: { items: 2 }
};
return (
<AliceCarousel
items = {items}
mouseDragEnabled
responsive={responsive}
buttonsDisabled={true}
dotsDisabled={true}
/>
)
}
You've forgot to return checkImage.map
from galleryItems
: 您忘记了从
galleryItems
return checkImage.map
galleryItems
:
galleryItems() {
return (
this.state.brands.map((brand, i) => {
// ...
return checkImage.map((image, i) => (
<div key={`key-${i}`} className="card-img-top">...</div>
));
})
)
};
The issue is that the first map
inside galleryItems
does not return anything, so galleryItems
just returns an empty array. 问题是
galleryItems
内部的第一个map
不返回任何内容,因此galleryItems
仅返回一个空数组。 Thus nothing is rendered, but also no errors. 因此什么也没有呈现,也没有错误。
You can update it like this: 您可以像这样更新它:
galleryItems() {
return (
this.state.brands.map((brand, i) => {
var checkImage = brand.media.length === 0 ? [] : brand.media.filter((media) => media.collection_name === "images");
console.log('henlos',checkImage)
return checkImage.map((image, i) => (
<div key={`key-${i}`} className="card-img-top"><img src={image.url} /></div>
));
})
)
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.