• Element ui tree 搜索


    搜索框

    属性

      :filter-node-method="filterNode"  对树节点进行筛选时执行的方法,返回 true 表示这个节点可以显示,返回 false 则表示这个节点会被隐藏
               <el-input v-model="filterText"></el-input> 
              <el-tree ref="space"
                       id="modelTree"
                       :data="spaceTreeData"
                       :props="defaultProps"
                       show-checkbox
                       node-key="nodeId"
                       :default-expanded-keys="defaultExpandedKeys"
                       :expand-on-click-node="false"
                       :render-content="renderContent"
                       :filter-node-method="filterNode"
                       @node-click="handleNodeClick"></el-tree>

    数据

     data() {
        return {
          //空间树数据
          spaceTreeData: [],
          //默认树结构的输出格式
          defaultProps: {
            children: 'children',
            label: 'name'
          },
          filterText: '',
        }
      },

    方法

    //监听搜索框的查询参数变化,然后进行过滤
    watch:{
      filterText(val) {
          this.$refs.space.filter(val)
        }
    }

    filter触发过滤事件

    methods:{ 
    //优化之后的代码 不管有几级都可以适用,不过用了递归,量太大还是会崩溃,这个后续需要优化 filterNode(value, data, node) { if (!value) { return true } let level = node.level let _array = [] //这里使用数组存储 只是为了存储值。 this.getReturnNode(node, _array, value) let result = false _array.forEach(item => { result = result || item }) return result }, getReturnNode(node, _array, value) { let isPass = node.data && node.data.name && node.data.name.indexOf(value) !== -1 isPass ? _array.push(isPass) : '' this.index++ console.log(this.index) if (!isPass && node.level != 1 && node.parent) { this.getReturnNode(node.parent, _array, value) } }
    }

  • 相关阅读:
    springmvc
    POJ 3683 Priest John's Busiest Day
    POJ 3678 Katu Puzzle
    HDU 1815 Building roads
    CDOJ UESTC 1220 The Battle of Guandu
    HDU 3715 Go Deeper
    HDU 3622 Bomb Game
    POJ 3207 Ikki's Story IV
    POJ 3648 Wedding
    HDU 1814 Peaceful Commission
  • 原文地址:https://www.cnblogs.com/xuqp/p/11117504.html
Copyright © 2020-2023  润新知