2
Well, I’m only trying to return the first item of the sub-array but I’m not getting it, the natural method {{ itens[0].name }}
doesn’t work:
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="teste">
<ul>
<li v-for="conteudos in conteudo">{{conteudos.nome}}
<ul>
<li v-for="itens in conteudos.contribuidores">{{itens[0].name}}</li>
</ul>
</li>
</ul>
<script>
new Vue({
el: "#teste",
data: {
conteudo: [
{
"nome": "Zé",
"idade": 29,
"contribuidores": [
{
"name": "Jane Doe",
"phone": "888-555-1212",
"relationship": "spouse"
},
{
"name": "Justin Doe",
"phone": "877-123-1212",
"relationship": "parent"
}
]
}
]
}
});
</script>
items is a list of objects since the
for
is directed to contributors– Douglas Teles
From what I see in the code, items represents a contributors list object.
– Lucas
Iteration 1: items = { "name": "Jane Doe", "phone": "888-555-1212", "Relationship": "spouse" }, Iteration 2: items = { "name": "Justin Doe", "phone": "877-123-1212", "Relationship": "Parent" }
– Lucas
soon, items[0] is the first object, and I want the name of that object
– Douglas Teles
Items[0] does not exist in this scope. items ta representing a contributing object. ex: var items = contributors[0]
– Lucas
Try using this command: {{contributors[0]. name}}
– Lucas
Didn’t work no
– Douglas Teles