异步树
async getTreeOptions() {
const id = JSON.parse(sessionStorage.getItem('currentAuthority')).officeId
// let data = []
let res = {}
res = await queryTreeList({ id })
const temp = {}
temp.id = res.currentInfo.id
temp.label = res.currentInfo.name
temp.level = res.currentInfo.level
temp.children = null
this.treeOptions.push(temp)
},
async loadOptions({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) {
let data = []
const arr = []
let res = {}
res = await queryTreeList({ id: parentNode.id })
data = res.levelList
for (const index of data) {
console.log(index)
const child = {}
child.id = index.id
child.label = index.name
child.level = index.level
child.children = null
arr.push(child)
}
parentNode.children = arr
callback()
}
},
这段代码展示了如何异步获取并处理树形数据。首先通过`getTreeOptions`方法获取当前权限对应的树节点信息,并将根节点添加到树选项中。然后在`loadOptions`方法中,根据父节点加载子节点数据,进行遍历和处理,最后更新父节点的子节点列表。整个过程涉及到的数据包括节点ID、名称、层级等关键信息。
3604

被折叠的 条评论
为什么被折叠?



