有什么方法可以访问 react-native 中的对象属性数组?

古鲁达

我是 react-native 编程的新手。我发现更困难的是访问 react-native 中的对象数组。我正在开发一个简单的 react-native 应用程序,我提出了一个 localhost 服务器请求,但在服务器响应中,我得到了对象数组。我尝试使用普通的 JavaScript 句点运算符访问这些对象数组。但是,我不允许我们访问这些对象。

我将在下图所示的对象数组中访问的属性。 在此处输入图片说明

在这里,我使用 localhost 服务器请求

 export default class Gallery extends Component{
  constructor(props){
    super(props);
    this.state = {
      data: []
    }
  }

  componentWillMount(){
    fetch('http://139.162.27.183:8080/Eshiksha/org/'+this.props.orgId+'/branch/'+this.props.branchId+'/videourl/videourls', { 'method' : 'GET', 
          headers: {
            'Content-Type' : 'application/json',
            'Authorization' : this.props.auth
          }
     })
    .then((response) => response.json())
    .then((responseData) => {
      this.setState({ data: responseData });
      console.log(this.state.data.videoUrls[4]); // Using Remote JS Debugging i consoled out following array of object it's shown. But same code (this.state.data.videoUrls[4]) not being accessed within the render function.
    })
    .done();
  }

    render(){
        return(
        <ScrollView>
            <View style={styles.container}>
                <View style={styles.card}>
                  <View style={styles.button}>
                    <Text style={styles.buttonText}>{this.state.data.videoUrls[4].eventName}</Text> // Here, I'm getting error which is shown below image
                  </View>
                <TouchableOpacity>
                  <View style={styles.button}>
                    <Image style={styles.image} source={require('./school.jpg')} />
                  </View>
                </TouchableOpacity>
                </View>
            </View>
        </ScrollView>
        );
    }
}

在 react-native render() 函数中,我试图访问服务器响应数据中的那些对象数组。在这里,我收到以下错误,如下图所示。在此处输入图片说明

请帮我找到一个解决方案来访问 react-native 中的那些对象属性数组。提前致谢...

艾伯克·阿尼尔·阿齐兹

那应该运行。您首先检查状态内是否准备好响应。如果您的响应准备就绪,您可以更改状态。检查代码。

        constructor(props){
            super(props);
            this.state = {
              data: [],
              isReady:false,  //create isReady on the state
            }     

        componentWillMount(){
                fetch('http://139.162.27.183:8080/Eshiksha/org/'+this.props.orgId+'/branch/'+this.props.branchId+'/videourl/videourls', { 'method' : 'GET', 
                      headers: {
                        'Content-Type' : 'application/json',
                        'Authorization' : this.props.auth
                      }
                 })
                .then((response) => response.json())
                .then((responseData) => {
                  this.setState({ data: responseData, isReady:true}); //when response came change the status.
                })
                .done();
              }

            render(){
                const {isReady} = this.state; //check the state if response is ready render your scrollview
               if(isReady)
                return(
                <ScrollView>
                    <View style={styles.container}>
                        <View style={styles.card}>
                          <View style={styles.button}>
                            <Text style={styles.buttonText}>{this.state.data.videoUrls[4].eventName}</Text> // Here, I'm getting error which is shown below image
                          </View>
                        <TouchableOpacity>
                          <View style={styles.button}>
                            <Image style={styles.image} source={require('./school.jpg')} />
                          </View>
                        </TouchableOpacity>
                        </View>
                    </View>
                </ScrollView>
                );
               return(
                  <View/>
               )
            }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我可以从Realm React Native中嵌套对象架构上的Relationship方法访问具有循环引用的属性对象吗

来自分类Dev

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

来自分类Dev

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

来自分类Dev

如何更改数组javascript中对象的属性(React Native)

来自分类Dev

访问要在React Native Text组件中显示的对象数组

来自分类Dev

有什么方法可以在React中访问父组件实例?

来自分类Dev

有什么方法可以在react-native-webview中禁用hapticFeedback

来自分类Dev

JSON对象-在React Native中访问值

来自分类Dev

React-Native从数组中删除对象

来自分类Dev

在 React Native 中显示嵌套对象数组中的所有数据

来自分类Dev

在Realm for React Native上过滤具有null属性的对象

来自分类Dev

如何检查数组是否具有相同的对象React Native

来自分类Dev

在对象数组中,如何在React中按属性返回所有对象?

来自分类Dev

为什么在React Native中存储对象数组时AsyncStorage会给出一个空数组

来自分类Dev

在React Native View中显示对象数组中的数据

来自分类Dev

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

来自分类Dev

获取 state 对象中定义的属性数量 react native

来自分类Dev

将数组对象渲染到FlatList React Native中

来自分类Dev

使用splice react native从数组中删除对象元素

来自分类Dev

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

来自分类Dev

无法在react-native中呈现对象数组

来自分类Dev

在React Native中对对象数组进行动画处理

来自分类Dev

在 React Native 中创建对象

来自分类Dev

无法使用useRef挂钩访问React Native中的scrollToIndex()方法

来自分类Dev

React-Native:for 循环中的 this.something.map 以访问 .json 文件中的数据数组中的数据。有人可以建议示例代码吗?

来自分类Dev

访问数组中的对象属性

来自分类Dev

访问数组中对象的属性

来自分类Dev

访问数组中的对象属性

来自分类Dev

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

Related 相关文章

  1. 1

    我可以从Realm React Native中嵌套对象架构上的Relationship方法访问具有循环引用的属性对象吗

  2. 2

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

  3. 3

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

  4. 4

    如何更改数组javascript中对象的属性(React Native)

  5. 5

    访问要在React Native Text组件中显示的对象数组

  6. 6

    有什么方法可以在React中访问父组件实例?

  7. 7

    有什么方法可以在react-native-webview中禁用hapticFeedback

  8. 8

    JSON对象-在React Native中访问值

  9. 9

    React-Native从数组中删除对象

  10. 10

    在 React Native 中显示嵌套对象数组中的所有数据

  11. 11

    在Realm for React Native上过滤具有null属性的对象

  12. 12

    如何检查数组是否具有相同的对象React Native

  13. 13

    在对象数组中,如何在React中按属性返回所有对象?

  14. 14

    为什么在React Native中存储对象数组时AsyncStorage会给出一个空数组

  15. 15

    在React Native View中显示对象数组中的数据

  16. 16

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

  17. 17

    获取 state 对象中定义的属性数量 react native

  18. 18

    将数组对象渲染到FlatList React Native中

  19. 19

    使用splice react native从数组中删除对象元素

  20. 20

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

  21. 21

    无法在react-native中呈现对象数组

  22. 22

    在React Native中对对象数组进行动画处理

  23. 23

    在 React Native 中创建对象

  24. 24

    无法使用useRef挂钩访问React Native中的scrollToIndex()方法

  25. 25

    React-Native:for 循环中的 this.something.map 以访问 .json 文件中的数据数组中的数据。有人可以建议示例代码吗?

  26. 26

    访问数组中的对象属性

  27. 27

    访问数组中对象的属性

  28. 28

    访问数组中的对象属性

  29. 29

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

热门标签

归档