1.3.9 • Published 4 years ago

react-do-tree-select v1.3.9

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

react-do-tree-select

A tree select React component.

NPM version NPM license NPM total downloads

简体中文

Features

  • Support a large amount of data (1000,000 pieces of data were tested for stability)
  • Support half-selection (even if the child nodes are all selected, the check of parent level will not be affected)

Demo

Install

npm install react-do-tree-select --save

# or

yarn install react-do-tree-select

react-do-tree-select depends on React

Examples

Here's simple example to get you started.

import React from 'react';
import TreeSelect from 'react-do-tree-select';
import Data from './Data';

class MyComponent extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            treeData: [],
            selectVal: '',
            showlevel: 0,
        }
        this.onSelect = this.onSelect.bind(this);
        this.onExpand = this.onExpand.bind(this);
        this.onChecked = this.onChecked.bind(this);
        this.customTitleRender = this.customTitleRender.bind(this);
    }

    componentDidMount() {
        const treeData = Data;
        this.setState({treeData});
    }
  
    customTitleRender(item) {
        return item.title
    }

    onSelect(val, e) {
        console.log(val);
    }

    onExpand(val, e) {
        console.log(val);
    }

    onChecked(val, e) {
        console.log(val);
    }

    render() {
        return (
            const { treeData, showlevel } = this.state;
            const checkbox = {
                enable: true,
                parentChain: true,              // child Affects parent nodes;
                childrenChain: true,            // parent Affects child nodes;
                halfChain: true,                // The selection of child nodes affects the semi-selection of parent nodes.
                initCheckedList: []             // Initialize check multiple lists
            }
            return (
                <div className="App">
                    <TreeSelect
                        treeData            = {treeData}
                        style               = {{width: 320,height: 600}}
                        selectVal           = {this.state.selectVal}
                        onSelect            = {this.onSelect}
                        onExpand            = {this.onExpand}
                        onChecked           = {this.onChecked}
                        checkbox            = {checkbox}
                        showlevel           = {showlevel}
                        customTitleRender   = {this.customTitleRender}/>
                </div>
            );
        );
    }
}

./Data.js

export default [
    {
        title: '广东省',
        value: '1',
        children: [
            {
                title: '广州市',
                value: '1-1',
                children: [
                    {
                        title: '越秀区',
                        value: '1-1-1',
                    },{
                        title: '白云区',
                        value: '1-1-2',
                    }
                ]
            },{
                title: '珠海市',
                value: '1-2',
                disabled: true,
            },{
                title: '深圳市',
                value: '1-3',
            }
        ]
    },{
        title: '广西省',
        value: '2',
        children: [
            {
                title: '南宁市',
                value: '2-1',
            },{
                title: '桂林市',
                value: '2-2',
            },{
                title: '玉林市',
                value: '2-3',
            }
        ]
    }
]

API

propertydescriptiontypedefaultrequired
treeDatasource data configarray-true
showlevelHierarchy of expansionnumber0
checkboxCheck box config configobject-
wrapperClassNameExtended class namestring-
selectValSelected itemsstring-
styleCustom styleobject{width: 320, height: 800}
onSelectClick the event callback functionfunction( item, event )-
onExpandIcon Click the event callback functionfunction( item, event )-
onCheckedCheck the callback function for the eventfunction( items, event )-
customIconRenderThe custom icon is extended after the entryfunction(item) : DOM-
customTitleRenderDisplays the title of the entryfunction(item) : DOM-

treeData

propertydescriptiontypedefaultrequired
titleItem titlestring-
valueThe unique identity of the itemstring-
disabledWhether the item is disabledboolfalse
childrenItem childrenarray-

checkbox

propertydescriptiontypedefaultrequired
enableSwitch the check boxboolfalse
parentChainchild Affects parent nodesbooltrue
childrenChainparent Affects child nodesbooltrue
halfChainThe selection of child nodes affects the semi-selection of parent nodesbooltrue
initCheckedListInitialize check multiple listsarray-

License

react-do-tree-select is available under the MIT License.

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago