Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select全选功能 #6

Open
Chauncydecat opened this issue May 20, 2021 · 0 comments
Open

Select全选功能 #6

Chauncydecat opened this issue May 20, 2021 · 0 comments

Comments

@Chauncydecat
Copy link

#####我尝试通过高阶组件实现Select全选功能,可惜antd2.x并不支持,能否在vtx-ui2.x版本中加入这个功能?

import React from 'react'
import { Select } from 'antd'
const { Option } = Select

class SelectAll extends React.Component {
    constructor(props) {
        super(props)
    }
    componentDidMount() {
        // console.log(this.props.children)
    }
    componentDidUpdate() {
        console.log('selectChildren', this.props.children)
    }
    onChange = (key, item) => {
        if (key.includes('all')) {
            if (this.props.value?.length === this.props.children?.length) {
                this.props.onChange([])
            } else {
                let keyArr = this.props.children?.map(x => {
                    return x.key
                })
                this.props.onChange(keyArr)
            }
        } else {
            this.props.onChange(key)
        }
    }

    render() {
        console.log('this.props.children>>>>>>>>>', this.props.children);
        return (
            <Select mode="multiple" {...this.props} onChange={this.onChange}>
                <Option key="all">
                    全选
                </Option>
                {!!this.props.children?.length ? this.props.children : null}
            </Select>
        )
    }
}
export default SelectAll;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant