【发布时间】:2017-06-22 16:09:39
【问题描述】:
我得到类似这样的数据,并说我得到了无限组的深度。
data/group.data.json
module.exports = [
{
id: '1',
title: 'Awesome Group',
type: '1',
groups: [
{
id: '5',
title: 'Child in Level Two - A',
type: '2',
groups: [
{
id: '6',
title: 'Child in Level Three - A',
type: '2',
},
{
id: '8',
title: 'Child in Level Three - B',
type: '2',
}
]
},
{
id: '7',
title: 'Child in Level Two - B',
type: '2',
}
]
},
{
id: '2',
title: 'Rockers',
type: '2',
},
{
id: '3',
title: 'Dazzlers',
type: '3',
}
];
我不能像下面这样手动执行此操作,如何动态迭代它直到结束?
<ul class="list-group list-group-flush">
<template v-for="group in groupData">
<a class="list-group-item" href="#">
<h6>{{group.title}}</h6>
</a>
<template v-for="group in group.groups">
<a class="list-group-item pl-40" href="#">
<h6>{{group.title}}</h6>
</a>
<template v-for="group in group.groups">
<a class="list-group-item pl-60" href="#">
<h6>{{group.title}}</h6>
</a>
</template>
</template>
</template>
</ul>
<script>
let groupData = require('../data/group.data');
export default {
data () {
return {
groupData,
}
}
}
</script>
我想要一个答案,但不确定如何在我的情况下使用:https://stackoverflow.com/a/13523953/1292050
【问题讨论】:
-
我认为使用 N>3 的 N 维数组不太实用。你应该尝试重构你的数据
-
你应该研究如何编写递归组件:vuejs.org/v2/examples/tree-view.html
标签: javascript vue.js vuejs2