lycHub / ysx-library

ysx component libraries
MIT License
19 stars 9 forks source link

How to callback to load async data #9

Open clabnet opened 9 months ago

clabnet commented 9 months ago

I have this tree

 <vir-tree
        ref="virtualTree"
        :source="treeItemsNoChild"
        :default-selected-key="defaultSelectedKey"
        :load-data="cbGetChildren"
        :virtual="{ size: 26, remain: 22 }"
      />

To call the cbGetChildren method is required the await because it need to wait the API response.

  const cbGetChildren = (node: BaseTreeNode, callback: (children: TreeNodeOptions[]) => void) => {
    console.log('[cbGetChildren]', node.key, node)
    let result: TreeNodeOptions[] = []
    const filter = '?level=1&name=FUQF.ALB.02.201B&parent=H-FUQF'
    console.log('[cbGetChildren] filter:', filter)
    const { data } = useAxios<TreeNodeOptions[]>(`/api/bom/lite${filter}`, config.axios, { immediate: false })
    result = data.value
    console.log('[cbGetChildren] result:', result)
    setTimeout(() => {
      callback(result)
    }, 200)
  }

Sorry for the dumb question: how to invoke the callback function with the 'async' and 'await' keywords ?

Thank's in advance