Created
November 18, 2018 19:04
-
-
Save hawkeye64/289ef21a5215e38652f218a6c88bbdc5 to your computer and use it in GitHub Desktop.
expand QTree method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expandTree: function (absolutePath) { | |
// get parts for the path | |
let parts = absolutePath.split(path.sep) | |
let path2 = '' | |
let lastNodeKey | |
// iterate through the path parts. | |
// This code will get the node. If the node is not found, | |
// it forces lazy-load by programmatically expanding | |
// the parent node. | |
for (let index = 0; index < parts.length; ++index) { | |
if (parts[index].length === 0) { | |
continue | |
} | |
if (index === 0) { | |
path2 += parts[index] + path.sep | |
} | |
else { | |
if (path2[path2.length - 1] !== path.sep) { | |
path2 += path.sep | |
} | |
path2 += parts[index] | |
} | |
if (index > -1) { | |
if ('folders' in this.$refs) { | |
const key = this.$refs.folders.getNodeByKey(path2) | |
// if we get key, then this folder has already been loaded | |
if (key) { | |
lastNodeKey = key | |
} | |
// handle folder not expanded | |
if (!this.$refs.folders.isExpanded(lastNodeKey.nodeKey)) { | |
this.$refs.folders.setExpanded(lastNodeKey.nodeKey, true) | |
if (path2 === absolutePath) { | |
this.selected = absolutePath | |
} | |
else { | |
this.$nextTick(() => { | |
this.$root.$emit('expand-tree', absolutePath) | |
}) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment