我正在尝试创建具有三个以上嵌套级别的嵌套列表。当我在v-list的子项中放置项的子项对象时,它什么也不显示。
甚至可以在vuetify中创建这样的嵌套列表吗?如果没有,该问题有什么解决方案?
<div>
<v-list v-for="(powerPlant, i) in powerPlants" :key="i">
<v-list-group
prepend-icon="fas fa-bolt"
value=""
>
<v-list-tile slot="activator">
<v-list-tile-title>{{powerPlant.name}}</v-list-tile-title>
</v-list-tile>
<v-list-group
no-action
sub-group
value="true"
v-for="(generator, i) in generators" :key="i"
>
<v-list-tile slot="activator">
<v-list-tile-title>{{generator.name}}</v-list-tile-title>
</v-list-tile>
<v-list-tile
v-for="(option, i) in options"
:key="i"
>
<v-list-tile-title v-text="option[0]"></v-list-tile-title>
<v-list-tile-action>
<v-icon v-text="option[1]"></v-icon>
</v-list-tile-action>
</v-list-tile>
</v-list-group>
</v-list-group>
</v-list>
</div>
如果有另一种方法可以使用Vue.js而不使用jQuery创建大型嵌套列表,我想学习。
对不起,您无法解释清楚。这样,一个已发布的列表可以达到3个级别,但是我不能再像4个或5个级别了。
答案 0 :(得分:0)
我通过嵌套v-list这样解决了这个问题:
<v-list>
<v-list-group v-for='node in nodes' v-model='node.active'>
<v-list-tile slot='activator' @click=''>
<v-list-tile-title>{{node.text}}</v-list-tile-title>
</v-list-tile>
<v-list class='py-0 pl-1'>
<v-list-group v-for='child in node.children' v-model='child.active'>
<v-list-tile slot='activator' @click=''>
<v-list-tile-title>{{child.text}}</v-list-tile-title>
</v-list-tile>
<v-list class='py-0 pl-2' v-for='grandchild in child.children'>
<v-list-tile>
<v-list-tile-title>{{grandchild.text}}</v-list-tile-title>
</v-list-tile>
</v-list>
</v-list-group>
</v-list>
</v-list-group>
</v-list>
这可以任意深入。实际上,我需要一个无限嵌套的列表,所以我创建了这个简单的递归组件:
<template>
<v-list>
<template v-for='node in nodes'>
<v-list-group v-if='node.children && node.children.length' v-model='node.active'>
<v-list-tile @click='' slot='activator'>
<v-list-tile-title>{{node.text}}</v-list-tile-title>
</v-list-tile>
<node-list class='py-0 pl-3' :nodes='node.children'/>
</v-list-group>
<v-list-tile @click='' v-else>
<v-list-tile-title>{{node.text}}</v-list-tile-title>
</v-list-tile>
</template>
</v-list>
</template>
<script>
export default {
name: 'node-list',
props: ['nodes'],
}
</script>