tree 树形结构搜索 显示子集

  作者:chrispy

<el-input placeholder="搜索" v-model="filterText" style="width:calc(100% - 20px);margin:10px"></el-input><el-tree ref="tree" :data="

<el-input placeholder="搜索" v-model="filterText" style="width:calc(100% - 20px);margin:10px"></el-input>

<el-tree ref="tree" :data="treeData" node-key="id" accordion  :filter-node-method="filterNode"></el-tree>

filterNode (value, data, node) { // 搜索

// 如果共有三级菜单

if (!value) return true

value = value.toLowerCase()

data = data.label.toLowerCase()

let ifOne = data.indexOf(value) !== -1

let ifTwo = node.parent && node.parent.data && node.parent.data.label && (node.parent.data.label.indexOf(value) !== -1)

let ifThree = node.parent && node.parent.parent && node.parent.parent.data && node.parent.parent.data.label && (node.parent.parent.data.label.indexOf(value) !== -1)

let resultOne = false

let resultTwo = false

let resultThree = false

if (node.level === 1) {

resultOne = ifOne

} else if (node.level === 2) {

resultTwo = ifOne || ifTwo

} else if (node.level === 3) {

resultThree = ifOne || ifTwo || ifThree

}

return resultOne || resultTwo || resultThree

},


猜你喜欢