ant-design/components/tree-select/demo/checkable.md
David Broder-Rodgers 654a675532 docs: Responsive fixes for examples pages (#19448)
* Remove fixed width from cascader examples

* Replace fixed vertical slider example height with clearfix div

* Replace fixed width on TreeSelect examples with percentage width

* Update test snapshots

* Use inline-block rather than float left for vertical slider example
2019-10-29 11:24:06 +08:00

1.3 KiB

order title
3
zh-CN en-US
可勾选 Checkable

zh-CN

使用勾选框实现多选功能。

en-US

Multiple and checkable.

import { TreeSelect } from 'antd';

const { SHOW_PARENT } = TreeSelect;

const treeData = [
  {
    title: 'Node1',
    value: '0-0',
    key: '0-0',
    children: [
      {
        title: 'Child Node1',
        value: '0-0-0',
        key: '0-0-0',
      },
    ],
  },
  {
    title: 'Node2',
    value: '0-1',
    key: '0-1',
    children: [
      {
        title: 'Child Node3',
        value: '0-1-0',
        key: '0-1-0',
      },
      {
        title: 'Child Node4',
        value: '0-1-1',
        key: '0-1-1',
      },
      {
        title: 'Child Node5',
        value: '0-1-2',
        key: '0-1-2',
      },
    ],
  },
];

class Demo extends React.Component {
  state = {
    value: ['0-0-0'],
  };

  onChange = value => {
    console.log('onChange ', value);
    this.setState({ value });
  };

  render() {
    const tProps = {
      treeData,
      value: this.state.value,
      onChange: this.onChange,
      treeCheckable: true,
      showCheckedStrategy: SHOW_PARENT,
      searchPlaceholder: 'Please select',
      style: {
        width: '100%',
      },
    };
    return <TreeSelect {...tProps} />;
  }
}

ReactDOM.render(<Demo />, mountNode);