Created
February 10, 2018 15:30
-
-
Save alonat/af3bc20722d2afe88450d8e888529472 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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