Я пытаюсь получить несколько атрибутов (order_id) из нескольких объектов в массиве json, который также присутствует внутри другого объекта json, и после этого добавить эти атрибуты в плоский список.Структура json выглядит так:
"data": {
"orders": [
{"order_id": "30", }
{"order_id": "31", }
{"order_id": "32", }
]
}
state={
data: []
};
componentWillMount() {
this.fetchData();
}
fetchData = async ()=> {
const response = await fetch("myurl" , {
method: 'POST' ,
body : {
access_token : 'token-value'
}
})
const json = await response.json();
this.setState({dat : json.data});
}
render(){
return(
<View style={{flex:1 , alignItem: "center" , justifyContent: "center" , alignSelf: "center" }}>
<View style={{flex:1 , flexDirection: 'column'}}>
<FlatList
dat={this.state.dat}
keyExtractor={(x,i) => i}
renderItem={({item}) => <Text>
{item.orders[0].name}</Text>}
/>`enter code here`
</View>
</View>
) ;
}