This is connected to How to get value if key? which I can use to display the correct measurement to the correct box.
I have a user profile card that displays different measurements in boxes, such as temperature, volume and weight.
Currently I’m getting the name of each user from an axios GET request, I need to then take the ID in that data and perform another GET request with the ID which gives me a performance data, in that data I am given a performance ID which I need to use to GET a final array of measurement data.
But I’m wondering how I can take the data of the measurements and display in each user profile{that has measurement data) for each measurement box? For example lets say I have 3 objects of profile details and 2 of measurement data, how can I show the measurement data with performance ID 2 to profile ID 3?
It looks something like this:
- I make the first axios request in vuex and use v-for to display each user name:
GET api/profiles
which returns:
"data": [
{
"id": 1,
"name": "Joe",
},
{
"id": 2,
"name": "Max",
},
<div class="outer" v-for="(item, index) in profiles" :key="item.id" >
<p> User Name: {{ item.name }}</p>
- I then need to make another GET request for performance:
GET api/performance/{profileID}
which returns only for users who have (other users return empty data object):
mounted() {
this.$store.state.profiles.forEach((item, index) => {
axios.get('api/performance/' + this.profile[index].id)
.then(response => {
this.performanceId = response.data.data.id
})
});
}
"data": {
"id": 1,
"profile_id": 2,
.....other keys and values
}
- and lastly for the users that have a performance ID I need to get the measurements:
GET api/measurements/{profileID}/{performanceID}
which returns for Max:
"data": {
"profileID": "2",
"perfomanceID": "1",
"data": [
{
"key": "temp",
"data": "37",
},
{
"key": "vol",
"data": "22",
},
{
"key": "weight",
"data": "200",
},
I would then like each data point to display in the box:
<div class="outer" v-for="(item, index) in profiles" :key="item.id" >
<p> User Name: {{ item.name }}</p>
<div class="box 1">Temperature: </div>
<div class="box 2">Volume: </div>
<div class="box 3">Weight: </div>
</div>
The end result would look like:
User Name: Max User Name: Joe
Temperature: 37 Temperature: 36.5
Volume: 22 Volume: N/A
Weight: 200 Weight: 150
The requests all together:
created(){
axios.get('/api/api/profiles/').then(res => this.profiles = res.data.data).then(
this.profiles.forEach((item, index) => {
axios.get('api/api/performance/' + item.id)
.then(response => { if(response.data.data) {
axios.get('api/api/measurements/' + item.id + "/" + response.data.data.id)
.then(response => {if(response.data.data) {response.data.data) })}
});
}))
},
Any help would be appreciated, thanks!