<a-tree v-if="loading" checkable multiple @select="onSelect" @check="onCheck" @rightClick="rightHandle" :selectedKeys="selectedKeys" :checkedKeys="checkedKeys"
:treeData="departTree" :checkStrictly="checkStrictly" :expandedKeys.sync="iExpandedKeys" :load-data="loadSubTree" @expand="onExpand" />
使用 :load-data 属性
方法一:
loadSubTree(treeNode) {
var that = this
return new Promise((resolve) => {
queryDepartTreeSync({ pid: treeNode.dataRef.id }).then((res) => {
if (res.success) {
//判断chidlren是否为空,并修改isLeaf属性值
if (res.result.length == 0) {
treeNode.dataRef['isLeaf'] = true
return
} else {
treeNode.dataRef['children'] = res.result
}
for (let i = 0; i < res.result.length; i++) {
let temp = res.result[i]
that.allIds.push(temp.key)
if (that.loadTreeKeys.indexOf(temp.key) > 0) {
that.iExpandedKeys.push(temp.key)
}
}
}
})
resolve()
})
//保存全部部门信息,方便后面搜索使用
that.departTreeAll = that.departTree
},
方法二:
onLoadData(treeNode) {
let _that = this
return new Promise((resolve) => {
if (!treeNode) {
resolve()
return
}
//直接调用接口
getAction(_that.url.treeList, { tableId: tableId }).then((res) => {
if (res.success && res.result) {
treeNode.dataRef.children = res.result
//metaDataTree tree-data的数据
_that.metaDataTree = [..._that.metaDataTree]
resolve()
}
})
})
},