this.setCheckedKeys([1,2,3,4,5])
一级
setCheckedKeys (menuIds) { // menuIds数组,id
var menuArr = [];
for (let j = 0; j < menuIds.length; j++) {
menuArr.push(menuIds[j])
}
this.menuArr=menuArr
this.$refs.tree.setCheckedKeys(menuArr);
this.check =this.$refs.tree.getCheckedKeys()
},
二级(树结构)
//设置选中的id
setCheckedKeys (menuIds) {
var menuArr = [];
for (let j = 0; j < menuIds.length; j++) {
const menuid = menuIds[j];
let key = this.getNodekeys(menuid, this.qxData);
if (key != '') {
menuArr.push(key);
}
}
this.$refs.tree.setCheckedKeys(menuArr);
},
//获取选中的孩子节点
getNodekeys (menuId, childrens) {
var key = "";
for (let i = 0; i < childrens.length; i++) {
const menu = childrens[i];
let id = menu.menu_id;
let childs = menu.item;
if (id == menuId) {//如果相等
if (childs && childs.length > 0) {
key = this.getNodekeys(menuId, childs)
} else { //没有孩子节点
return menuId;
}
} else if (childs && childs.length > 0) {
key = this.getNodekeys(menuId, childs);
}
if (key != '') {
return key;
}
}
return key;
},
清空
this.$refs.tree.setCheckedKeys([])