• element树形筛选


    1. <el-input
    2. v-model="projectName"
    3. placeholder="请输入名称"
    4. clearable
    5. maxlength="10"
    6. @clear="clearTree"
    7. />
    8. <el-divider />
    9. <el-tree
    10. ref="tree"
    11. class="filter-tree"
    12. :data="treeList"
    13. :props="defaultProps"
    14. default-expand-all
    15. node-key="id"
    16. :highlight-current="highlightCurrent"
    17. :filter-node-method="filterNode"
    18. @node-click="handleNodeClick"
    19. >
    20. <div slot-scope="{ node, data }" class="custom-tree-node" :title="node.label">
    21. <span>{{ node.label }}span>
    22. <div class="button-group" @click.stop="() => {}">
    23. <el-link size="mini" type="primary" icon="el-icon-circle-plus-outline" @click.stop="onAddType(data)" />
    24. <el-link size="mini" type="primary" icon="el-icon-delete" @click.stop="onDelType(data)" />
    25. div>
    26. div>
    27. el-tree>
    1. projectName: '',
    2. treeList: [],
    3. defaultProps: {
    4. children: 'children',
    5. label: 'name'
    6. },
    7. watch: {
    8. projectName: {
    9. handler(v) {
    10. // 监听输入框变化、进行实时过滤
    11. this.$refs.tree.filter(v)
    12. }
    13. }
    14. },
    15. methods: {
    16. // 过滤掉无用的数据
    17. filterNode(value, data, node) {
    18. if (!value.trim()) return true
    19. if (data.name.toLowerCase().indexOf(value.toLowerCase().trim()) !== -1) { return true }
    20. return this.checkNodes(value, data, node)
    21. },
    22. // 筛选父级所需要的子级
    23. checkNodes(value, data, node) {
    24. const level = node.level
    25. if (level === 1) return false
    26. let parentData = node.parent
    27. let index = 0
    28. while (index < level - 1) {
    29. if (parentData.data.name.toLowerCase().indexOf(value.toLowerCase().trim()) !== -1) return true
    30. parentData = parentData.parent
    31. index++
    32. }
    33. return false
    34. },
    35. // 清空项目树搜索框
    36. clearTree() {
    37. this.getOrganizarionTree()
    38. },
    39. }
  • 相关阅读:
    正则系列之字符类
    如何获取用户的ip地址
    运行gazebo机器人模型没有cmd_vel话题
    feign整合sentinel做降级知识点
    记录一下自己涉及到的时间及金额方法的处理
    ACM笔记
    安装CentOS7虚拟机
    解锁新技能《SkyWalking-aop服务搭建》
    docker报错Error response from daemon: Container xxx is not running
    MySQL 查询优化思路
  • 原文地址:https://blog.csdn.net/Guoyu1_/article/details/132739458