ant-design/components/tree-select/demo/checkable.md

69 lines
1.3 KiB
Markdown
Raw Normal View History

2015-12-28 19:16:02 +08:00
# 更多功能
- order: 1
更多功能。
---
````jsx
import { TreeSelect } from 'antd';
2015-12-31 14:38:35 +08:00
const x = 3;
const y = 2;
const z = 1;
2016-02-01 14:36:41 +08:00
const gData = []; // 手工构造数据
2015-12-28 19:16:02 +08:00
const generateData = (_level, _preKey, _tns) => {
const preKey = _preKey || '0';
const tns = _tns || gData;
const children = [];
for (let i = 0; i < x; i++) {
const key = `${preKey}-${i}`;
2016-02-01 14:36:41 +08:00
tns.push({
label: key + '-label',
value: key + '-value',
key: key,
});
2015-12-28 19:16:02 +08:00
if (i < y) {
children.push(key);
}
}
if (_level < 0) {
return tns;
}
const __level = _level - 1;
children.forEach((key, index) => {
tns[index].children = [];
return generateData(__level, key, tns[index].children);
});
};
generateData(z);
const Demo = React.createClass({
getInitialState() {
return {
2016-02-01 14:36:41 +08:00
value: ['0-0-0-value'],
2015-12-28 19:16:02 +08:00
};
},
2015-12-31 14:38:35 +08:00
onChange(value) {
2016-02-01 14:36:41 +08:00
console.log('onChange ', value, arguments);
2016-01-23 15:30:14 +08:00
this.setState({ value });
2015-12-28 19:16:02 +08:00
},
render() {
2015-12-31 14:38:35 +08:00
const tProps = {
2016-02-01 14:36:41 +08:00
treeData: gData,
2015-12-31 14:38:35 +08:00
value: this.state.value,
onChange: this.onChange,
multiple: true,
2016-01-15 20:10:46 +08:00
treeCheckable: true,
2015-12-31 14:38:35 +08:00
treeDefaultExpandAll: true,
2015-12-28 19:16:02 +08:00
};
2016-01-21 17:14:39 +08:00
return (
2016-02-01 14:36:41 +08:00
<TreeSelect style={{ width: 360 }} {...tProps} />
2016-01-21 17:14:39 +08:00
);
2015-12-28 19:16:02 +08:00
},
});
2016-01-27 12:00:27 +08:00
ReactDOM.render(<Demo />, mountNode);
2015-12-28 19:16:02 +08:00
````