最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
vue elementUI tree树形控件获取父节点ID的实例
时间:2022-06-25 15:40:10 编辑:袖梨 来源:一聚教程网
首先找到element-ui.common.js文件 如下 具体看你工程下的node_modules
D:workSpacevue_managenode_moduleselement-uilibelement-ui.common.js
找到getCheckedNodes该方法 细节如下我的该方法在21618行
TreeStore.prototype.getCheckedNodes = function getCheckedNodes() {
var leafOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var checkedNodes = [];
var traverse = function traverse(node) {
var childNodes = node.root ? node.root.childNodes : node.childNodes;
childNodes.forEach(function (child) {
if (child.checked && (!leafOnly || leafOnly && child.isLeaf)) {
checkedNodes.push(child.data);
}
traverse(child);
});
};
traverse(this);
return checkedNodes;
};
修改 其中的if判断
TreeStore.prototype.getCheckedNodes = function getCheckedNodes() {
var leafOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var checkedNodes = [];
var traverse = function traverse(node) {
var childNodes = node.root ? node.root.childNodes : node.childNodes;
childNodes.forEach(function (child) {
if ((child.checked || child.indeterminate) && (!leafOnly || leafOnly && child.isLeaf)) {
checkedNodes.push(child.data);
}
traverse(child);
});
};
traverse(this);
return checkedNodes;
};
然后重启项目
console.log(this.$refs.tree.getCheckedKeys());就可以拿到父节点的ID啦
相关文章
- Ubuntu通过wine安装QQ无法输入账号怎么办? 09-12
- Ubuntu系统中WPS不能输入中文该怎么办? 09-12
- 快速释放Ubuntu磁盘空间的七种方法 09-12
- Ubuntu系统中怎么设置IP地址? 09-12
- ubuntu挂载移动硬盘出现错误 mountunknown filesystem type exfat 09-12
- ubuntu怎么进入指定的文件夹并更改路径? 09-12