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

Fetch data issue : Fetch data is called even when node has children

Open Sgad27 opened this issue 4 years ago • 2 comments

I am trying to get my child nodes async. When ever the user opens root node, I am hitting a service and getting children and grand children at the same time using the fetch data method as mentioned in the documentation. But when i open any of the children of the same node it calls fetch data method again even though grand children already exists and inserts the grand children once more causing duplication of data. Can you please help me resolve this issue? I tried adding a condition in fetch data method to hit the service only if node doesn't already have any children but as Fetch data expects an array i sent an empty array. But this throws an error saying "Cannot read property 'id' of undefined". Can we have check that if the fetched data is null then dont try to add anything to the tree? Can you please try to help me at your earliest convenience? Thank you.

Sgad27 avatar Sep 13 '19 10:09 Sgad27

Hi. Could you please show me a real example? Please use https://codesandbox.io or similar

amsik avatar Sep 18 '19 08:09 amsik

When having the grandchildren already, it worked for me by not returning anything in the fetchData function, and it automatically returns the corresponding values:

treeOptionsTop = {
    fetchData: this.fetchTreeData
}

async fetchTreeData (node) {
    if (!this.grandchildren) {
        let response = await axios.get(url)
        this.grandchildren = parseGrandchildrenFromTreeData(response.treeData)
        return response.treeData
    }
}

tamanakid avatar Oct 20 '20 08:10 tamanakid