GithubHelp home page GithubHelp logo

element-multi-select-tree's Introduction

element-multi-select-tree

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Main Parameter and Function

selectedData     // the label that shows on selection box
selectedNode     // the nodes array that user checked
selectedIds      // selected id arrays as search params
list             // origin data
handleTagChange  // a function to handle select items
handleCheckChange// a function to handle tree node check

Use element tree component as a slot in a select component

<el-select 
    v-model="selectedData"
    multiple
    :clearable="clearable"
    @remove-tag="handleTagChange"
    @clear="clearHandle">
    <el-input
        class="selectInput"
        :placeholder="placeholder"
        v-model="filterText">
    </el-input>
    <el-option :value="0" class="options">
        <el-tree id="tree-option"
        ref="selectTree"
        show-checkbox
        :accordion="accordion"
        :data="options"
        :props="defaultProps"
        :node-key="defaultProps.value"
        :default-expanded-keys="defaultExpandedKey"
        :filter-node-method="filterNode"
        @check="handleCheckChange">
        </el-tree>
    </el-option>
</el-select>

When you check a tree node, you should update the selection box

handleCheckChange: function(node, checkedNode) {
    this.selectedIds = this.$refs.selectTree.getCheckedKeys().filter(_ => _);
    this.selectedNode = this.$refs.selectTree.getCheckedNodes().filter(_ => _);
    this.selectedData = this.selectedNode.reduce((acc, cur)=>{
        acc.push(cur.name+ '(' + cur.id + ')')
        return acc
    }, [])
},

When you change your selected items, you should update the tree node status

handleTagChange: function(node) {
    let selectKeys = node.match(/\((.+?)\)/)[1]
    this.$refs.selectTree.setChecked(selectKeys, false)
    this.selectedIds = this.$refs.selectTree.getCheckedKeys().filter(_ => _);
    this.selectedNode = this.$refs.selectTree.getCheckedNodes().filter(_ => _);
    this.selectedData = this.selectedNode.reduce((acc, cur)=>{
        acc.push(cur.name+ '(' + cur.id + ')')
        return acc
    }, [])
},

Demo 展示


参考文献
Element UI框架中巧用树选择器
vue实现 Element-UI 的 Tree Select 树形选择器组件(一)组件封装

element-multi-select-tree's People

Contributors

zhangxinxing59 avatar

Stargazers

 avatar  avatar 罗文强 avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.