liquor-tree icon indicating copy to clipboard operation
liquor-tree copied to clipboard

get null when finding appended children in tree from API call

Open maikenmadsen1992 opened this issue 5 years ago • 1 comments

I have an array looking like this: [{text: books}, {text: fantasy}, {text: J.K Rolling},{text: Harry Potter}]

I then know the order is: books is the parent node with depth 0. fantasy is the second with depth of 1, etc.

For displaying the hole tree have to make an API call for every node to get the data for the hole tree.

data = [{text: books}, {text: fantasy}, {text: J.K Rolling},{text: Harry Potter}]
data.forEach((node, index) => {

this.addChildNodeWhenSearchingCategory(node).then(result => {
          var nodeOnTree = this.$refs.tree.find(node.text) <- the error happens the second time because the text: J.K Rolling dosent exist in the tree
          nodeOnTree.expand(); 
          nodeOnTree.append(result);
})
})

 async addChildNodeWhenSearchingCategory(node, nodeAfter) {

 /* In the first iteration it returns something like: [{text: crime}, {text: fantasy} etc.]  */
 /* In the second iteration it return something like: [{text: George R.R. Martin}, {text: J.K Rolling} etc.]*/
  return Promise.resolve(/* return the expected data */) 

});

Do anybody know how to get the updated tree after appending a child, I think thats my error?

maikenmadsen1992 avatar May 23 '19 15:05 maikenmadsen1992

Hi! Can you upload you example to https://codesandbox.io or similar?

amsik avatar May 24 '19 05:05 amsik