我刚接触反应本地编程。我发现更难的是以react-native方式访问对象数组。我正在研究一个简单的反应本机应用程序,我做了一个本地主机服务器请求,但在服务器响应中,我得到了对象数组。我试图使用普通的JavaScript周期运算符访问这些对象的数组。但是,我不允许我们访问这些对象。有什么办法可以访问react-native中的对象属性数组吗?
在这里,我去与本地主机服务器请求
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中的那些对象属性数组。在此先感谢...
您的渲染方法在请求前呈现视图。你应该检查响应是否准备就绪。你可以检查它。你可以在里面写日志来渲染方法。 –
它是如何做到的。请帮我 –
看看答案。如果是工作,请选择它来回答。 –