Reputation: 3903
I have an array with multiple objects, which also contain an array.
[
{
title : "some title",
items: [
{
"title" : "some title",
"value" : "some value"
}
]
},
{
title : "some title",
items: [
{
"title" : "some title",
"value" : "some value"
}
]
},
{
title : "some title",
items: [
{
"title" : "some title",
"value" : "some value"
}
]
}
],
[
{
title : "another title",
items: [
{
"title" : "some title",
"value" : "some value"
}
]
},
{
title : "another title",
items: [
{
"title" : "some title",
"value" : "some value"
}
]
},
{
title : "another title",
items: [
{
"title" : "some title",
"value" : "some value"
}
]
}
]
In my vue
-component I did this:
<ul>
<li v-for="group in data" :key="group.title">
<h3>{{group.title}}</h3>
<div>
<div v-for="item in group.items" :key="item.id"/>
{{ item.value }}
</div>
</li>
</ul>
this works fine so far, but now I don't want to split them up and just want to output all without the {{group.title}}
- kind of merge them together. How can I solve this?
Upvotes: 0
Views: 445
Reputation: 141
I am not sure if I understand your question correctly so let me try. If you do want to display all items' values of all objects in the array, there are two ways to achieve that.
<ul>
<template v-for="group in data" :key="group.title">
<li v-for="item in group.items" :key="item.id">
<div>
{{item.value}}
</div>
</li>
</template>
</ul>
<ul>
<li v-for="item in items" :key=item.id>
<div>
{{item.value}}
</div>
</li>
</ul>
...
...
computed: {
items: {
const newArr = []
for(let i = 0; i<data.length; i++) {
for(let j = 0; j<data[i].items.length; j++) {
newArr.push({
value: data[i].items[j].value,
id: `${i}-${j}`,
})
}
}
return newArr
}
}
Upvotes: 2