如何在React Native中使用this.state访问数组中的对象?

兰妮·威廉姆斯

我正在使用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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在React Native中使用数组映射JSON数据

如何在React Native中过滤对象数组?

如何在React Native中使用索引更改数组中的值

react-native如何在this.state {} <closed>中使用AsyncStorage获取数据

在React Native中使用嵌套对象访问多维数组

如何在React中使用对象数组渲染组件

如何在React Native中使用数组对象迭代数组

如何在componentWillMount中更新状态并在React Native的render函数中使用该值?

如何在React Native中获取对象数组中的对象

如何在react-native中使用嵌套映射函数中的else条件?

如何在React Native中使用setState()修改多维数组?

在React Native中访问对象的JSON数组

如何在React Native中使用其索引在useState中更新数组

如何在React Native中使用复选框检查FlatList中的单个项目?

在React Native中按对象数组中的索引访问对象

如何在React Native中使用异步存储更改Route.Js中的初始屏幕

如何在React Native中使用React钩子使用TextInput更改对象数组的特定字符串?

如何在React Native中从单独的组件创建对象数组?

在React Native中如何在示例应用程序中使用N个视图

如何在 react-native 中访问导航对象

如何在 JavaScript 地图函数中使用 React Native 中的复选框?

如何在React Native中使用功能组件的方法到类组件中?

如何在 React-Native 的屏幕上访问嵌套数组 JSON 数据中的嵌套对象

在 React Native 中,如何在 iOS 中使用带有模态的 KeyboardAvoidingView?

我如何在 onPress 中使用 react-native 中的两个事件?

如何在 React Native (Android) / Expo 项目中使用 FFmpeg 访问图像文件?

react native - 如何在元组数组中使用 React Hooks?

在 react native 中使用 react-native-qrcode-scanner 時如何在 Camera View 中添加文本

如何在 React Native 导航 v6 中的 React Native 类组件中使用 context 和 useTheme?