我正在使用react-native-snap-carousel,无法访问数组中的URL。我可以访问它们而无需其他对象,但是我需要它们为每个图像命名。
constructor(props)
{
super(props);
this.state = {
categoriesimages: [
{
name: 'business 1',
images:
'http://www.example.com/img/venture.jpg',
},
{
name: 'business 2',
images:
'http://www.example.com/img/venture.jpg',
},
{
name: 'business 3',
images:
'http://www.example.com/img/venture.jpg',
}
]
}
renderItem = ({ item }) => {
return (
<Image source={{ uri: item }} style={styles.logoStyle} />
);
}
<View>
<Carousel
inactiveSlideOpacity={0.6}
inactiveSlideScale={0.65}
firstItem={1}
sliderWidth={width}
itemWidth={width / 3}
data={this.state.categoriesimages['images']} // this is the problem
renderItem={this.renderItem}
containerCustomStyle={{ overflow: 'visible' }}
contentContainerCustomStyle={{ overflow: 'visible' }}
/>
</View>
我还是刚接触本地人,查找类似问题并没有得出正确答案。
在此this.state.categoriesimages['images']
,data参数接受array
格式。
现在,您正在尝试categoriesimages
使用索引访问images
因此,您需要将其替换为
data={this.state.categoriesimages}
和
renderItem={({item}) => console.log(item.images)}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句