我剛接觸反應本地編程。我發現更難的是以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中的那些對象屬性數組。在此先感謝...
您的渲染方法在請求前呈現視圖。你應該檢查響應是否準備就緒。你可以檢查它。你可以在裏面寫日誌來渲染方法。 –
它是如何做到的。請幫我 –
看看答案。如果是工作,請選擇它來回答。 –