V
V
Vyacheslav2017-10-12 09:12:40
Vue.js
Vyacheslav, 2017-10-12 09:12:40

Loop for vue tree?

Hello to all!
I need a tree from the comments on the site, I try to execute it through vue.js,
I follow the example from the off-docs https://ru.vuejs.org/v2/examples/tree-view.html
And everything would be fine, but I ran into a problem.
In the off dock, the data array starts with 1 value, in which there are nested children arrays

var data = {
  name: 'My Tree',
  children: [
    ...
  ]
}

In my case, the incoming data array consists of a set of elements, in which there is a subset of children
var data = [
  {
    name: 'My Tree',
    children: [
    ...
    ]
  },
  {
    name: 'My Tree',
    children: [
    ...
    ]
  }, 
]

And it seems like everything should be obvious, add v-for and go)
so it is, I added it,
but instead of getting a tree structure on the output, I get only the 1st level of comments,
I understand that the solution is somewhere on the surface, but for now Even I don’t finish pointing
out the mistake?
a working example is here: https://jsfiddle.net/ct1kcpe7/
thanks in advance ))
UPD:
yes, I forgot to say that if the isReplies check is replaced with comment.replies
'<ul v-if="isReplies" => '<ul v-if="comment.replies"

then it starts to see the nested level, but only the first, only one, and does not display any data.
Yes, and to do so is not according to Feng Shui))
But I assume that the dog is buried somewhere right here.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Gontarev, 2017-10-12
@nskarl

like this
https://jsfiddle.net/qs9dLb2b/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question