ElementUI tree 搜索节点并显示所有子节点
2021-08-03 本文已影响0人
Cherry丶小丸子
<el-tree :filter-node-method="filterNode"></el-tree>
/**
* tree 节点过滤
* @param {Object} value
* @param {Object} data
* @param {Object} node
*/
filterNode(value, data, node) {
if (!value) return true;
let one = data.label.indexOf(value) !== -1;
let two = node.parent && node.parent.data && node.parent.data.label && (node.parent.data.label.indexOf(value) !== -1);
let three = node.parent && node.parent.parent && node.parent.parent.data && node.parent.parent.data.label && (node.parent.parent.data.label.indexOf(value) !== -1);
let four= node.parent && node.parent.parent && node.parent.parent.parent && node.parent.parent.parent.data && node.parent.parent.parent.data.label && (node.parent.parent.parent.data.label.indexOf(value) !== -1);
let result_one = false;
let result_two = false;
let result_three = false;
let result_four = false;
if(node.level === 1) {
result_one = one;
}else if(node.level === 2) {
result_two = one || two;
}
return result_one || result_two;
}