Hi guys I'm trying to build Tree component in Vue, I'm having a little doubt now I have already built a recursive component, similar to this one, but more complex with checkboxes, drag drop etc
https://v2.vuejs.org/v2/examples/tree-view.html
But now I'm looking at some samples online and it looks of them are made by flattening nested json and making a Tree out of it
Like this one:
https://jsfiddle.net/fernando2684/p0k8szvj/43/
Hi here recursive builds array and then builds Tree out of it
recursive(obj, newObj, level, itemId, isExpend) {
let vm = this;
obj.forEach(function(o) {
if (o.children && o.children.length != 0) {
o.level = level;
o.leaf = false;
newObj.push(o);
if (o.id == itemId) {
o.expend = isExpend;
}
if (o.expend == true) {
vm.recursive(o.children, newObj, o.level + 1, itemId, isExpend);
}
} else {
o.level = level;
o.leaf = true;
newObj.push(o);
return false;
}
});
},
Could someone tell, what could be real benefit out of this, I see it could be easier to maintain and all the data in array is reactive since it is only in one level ???