I have an array of Data objects that contain another array of Attendance and I want to access the all attendance attributes. I need to be able to insert data into checkIn, checkOut and total hours that belong to the nested array called attendance. I unable to fetch these type of data from HTTP request please suggest and check my code. And I also wanted to know that how can we fetch multiple array data from JSON API?
"data": [
{
"id": 40,
"addEmployee": {
"firstName": "Divyanshu"
},
"attendances": [
{
"id": 615,
"checkIn": null,
"checkOut": "2020-04-17T04:54:15.000Z",
"totalHours": "NaN:NaN",
"date": "2020-04-17",
"status": "present",
"createdAt": "2020-04-16T13:57:30.000Z",
"updatedAt": "2020-04-17T04:54:15.000Z",
"userId": 40
}
]
},
{
"id": 21,
"addEmployee": {
"firstName": "Narayan"
},
"attendances": [
{
"id": 617,
"checkIn": "2020-04-17T05:20:45.000Z",
"checkOut": "2020-04-17T05:21:22.000Z",
"totalHours": "0:0",
"date": "2020-04-17",
"status": "present",
"createdAt": "2020-04-17T05:20:45.000Z",
"updatedAt": "2020-04-17T05:21:22.000Z",
"userId": 21
},
]
},
{
"id": 20,
"addEmployee": {
"firstName": "Himanshu"
},
"attendances": []
},
0'.v\zcfipzgzy
],
"status": 1
}
I am able to insert data to a normal array. But I don't know how to insert to a nested array and I unable to Access Attendance data from Above nested array data.
componentDidMount() {
const url = 'http://104.197.28.169:3000/todayAttendanceList'
fetch(url)
.then(response => response.json())
.then((responseJson) => {
console.log("aagiyo", responseJson)
this.setState({
dataSource: responseJson,
isLoading: false
})
})
.catch(error => console.log(error))
}
<FlatList
data={this.state.dataSource}
renderItem={({ item }) =>
<View style={styles.firstV1}>
<View style={styles.heading}>
<Text style={{ fontSize: 15 }}>{item.attendances.checkIn}</Text>
</View>
<View style={styles.heading}>
<Text style={{ fontSize: 15, }}>{item.attendances.checkOut}</Text>
</View>
<View style={styles.heading}>
<Text style={{ fontSize: 15 }}>{item.attendances.totalHours}</Text>
</View>
}
ItemSeparatorComponent={this.renderSeperator}
/>
