How can I properly access the nested JSON data for stage.name provided in the example below?
As shown in the template, my attempt to retrieve the stage name is not working.
Using vue.js
created() {
url="http://{{ api_endpoint }}"
fetch(url)
.then(response => response.json())
.then(body => {
for(i=0; i<body.length; i++){
this.job_execs.push({
'name': JSON.stringify(body[i].job.name),
'build_id': JSON.stringify(body[i].build_num),
'env': JSON.stringify(body[i].job.env),
})
}
})
template: `
<li v-for="item in this.job_execs">
[[ item.build_num ]]
<li v-if="stage in item.job">
[[ stage.name ]]
</li>
</li>
</ul>
An example API response:
[
{
"build_num": 12,
"job": {
"name": "test-job",
"env": "DEV",
"tool": {
"env": "DEV",
},
"product": {
"name": "vuejs"
},
"platform": {
"name": "none"
},
"stage": [
{
"name": "stage1"
},
{
"name": "stage2"
},
{
"name": "stage3"
},
]
},
]
I think I may need to create a new list in the created hook and start pushing the stage names into it. However, I am concerned about ending up with two separate lists. I'm uncertain about the best approach to take in this scenario.