Answer the question
In order to leave comments, you need to log in
How to display child elements from array in treeview (vuetify)?
Vuetify has a treeview component that allows you to display data on the selected element in a separate block - https://v15.vuetifyjs.com/en/components/treeview#a...
While I was studying, the question arose how to display child elements in this array , on the example of such a case:
https://codepen.io/denisemenov/pen/GRRQWEb
The first three lines work out as they should, and then sadness.
How to output this data by child elements?
Answer the question
In order to leave comments, you need to log in
Let's make a function that will perform a recursive search:
const find = (arr, id) =>
(Array.isArray(arr) ? arr : []).reduce((found, n) =>
found || (n.id === id ? n : find(n.children, id))
, null);
selected() {
return this.active.length
? find(this.users, this.active[0])
: null;
},
return-object
- then in active there will be objects instead of keys. Accordingly, there is no need to look for anything, the computed property will be reduced toselected() {
return this.active[0];
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question