Skip to content

How to callback to load async data #9

Description

@clabnet

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions