Skip to content

Instantly share code, notes, and snippets.

@alonat
Created February 10, 2018 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alonat/af3bc20722d2afe88450d8e888529472 to your computer and use it in GitHub Desktop.
Save alonat/af3bc20722d2afe88450d8e888529472 to your computer and use it in GitHub Desktop.
<template>
<ul>
<li v-for="item in levelItems">
{{ item.title }}
<tree :items="items"
:left="item.left"
:right="item.right">
</tree>
</li>
</ul>
</template>
<script>
import Tree from './Tree.vue';
export default {
name: 'tree',
components: { Tree },
props: {
items: {
type: Array,
required: true,
},
left: {
default: 0,
},
right: {
default: null,
},
},
computed: {
levelItems() {
return this.getArray(this.items, this.left, this.right);
},
},
methods: {
getArray(set, left = 0, right = null) {
const tree = [];
set.forEach((el) => {
if (el.left === (left + 1) &&
(right === null || el.right < right)) {
tree.push(el);
left = el.right;
}
});
return tree;
},
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment