我想列出包含对象的数组内的文本。我似乎无法弄清楚该如何解决,我可以接近...
例如
<template>
<div>
<ul>
<li v-for="(value, index) in otherclients" v-bind:key="index">
DATA = {{ value.doc.notes }}
</li>
</ul>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'Viewer',
computed: mapState({
otherclients: state => state.otherclients
})
}
</script>
<style lang="css" scoped></style>
将输出
但是我想要的是
但是我似乎无法找到进入最后一层的最佳方法。 任何指针都适用。这是一个更大的项目的一部分,因此为state.otherclients设置了结构,并且非常复杂。
答案 0 :(得分:0)
使用带有for
标签的嵌套template
循环
<template>
<div>
<ul>
<template v-for="(value, index) in otherclients">
<li v-for="(note, note_index) in value.doc.notes">{{note.text}}</li>
</template>
</ul>
</div>
</template>
var app = new Vue({
el: '#app',
data:{
name:'niklesh',
otherclients:[
{doc:{notes:[ { "id": "w5fpn80fnnf5nxdj9f1n1i", "text": "Welcome new device mydoc_android", "owner": "YOU", "deleted": false }, { "id": "w5fpn80fnnf5nxdj9f1wwwn1i", "text": "android 2", "owner": "YOU", "deleted": false } ]}},
{doc:{notes:[ { "id": "c1ds7zqd7tcgig0b1xs1q", "text": "Welcome new device mydoc_ios", "owner": "YOU", "deleted": false }, { "id": "nf5nxdj9f1dwwen1iw5fpn80fn", "text": "More Text", "owner": "YOU", "deleted": false } ]}},
]
}
});
//[[{text:'test11'},{text:'test12'}]},[{text:'test21'},{text:'test22'}]}]
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script>
<div id="app">
<ul>
<template v-for="(value, index) in otherclients">
<li v-for="(note, note_index) in value.doc.notes">{{note.text}}</li>
</template>
</ul>
</div>