zdy1988 / vue-jstree

A Tree Plugin For Vue2.0+

Home Page:http://zdy1988.github.io/vue-jstree

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic data loading into tree

aniketgupta opened this issue · comments

Hi @zdy1988

I am just getting all my data from back-end and pushing that into data, but i am not able to load the children of tree. Also i have tried using async, but in that case it is only loading one level of children not multiple levels. If possible can you suggest me some solution for this problem.

hey :)
with async thats no problem.
you just need to have multiple levels in your response

you just need to add you children with all properties in your response:

response: [ node: { isLeaf: false, opened: true, children: [ node: { isLeaf: false, opened: true, children: [ { "text": "Loading ...", "loading": true } ] }, ] }, node: { ... } ]

I have a similar problem.

When I set data
beforeCreate() { fetch('http://localhost:8000/api/capitulos') .then(result => result.json()) .then(rowdata => { this.data2 = JSON.parse(JSON.stringify(rowdata )) })

The data show well,

I can't create new element with method addChild, because no exist for those elements.

why are you using beforeCreate ?
why not creating a function with your logic in it and then setting it as async prop for tree.

then you get a callback for your function wich you need to call with result of you request
this should fix your issue

why are you using beforeCreate ?
why not creating a function with your logic in it and then setting it as async prop for tree.

then you get a callback for your function wich you need to call with result of you request
this should fix your issue

Because I am downloading data and showing all data at the same time, then can add, edit, remove, drag and drop and finally send data to api for save change when I click in button 'save'. it is my functionality.

if you want to do it like this, you still need to call the function yourself. (it sets default properities for data)
i would highly recommend using async data property because you can load all of the data with it - no difference. When you BackendAPI returns all data and not only one level it should be exactly the same