2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 1
|
2016-08-05 11:47:31 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 从数据直接生成
|
|
|
|
en-US: Generate form tree data
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2016-02-01 17:06:54 +08:00
|
|
|
|
2016-08-05 11:47:31 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2016-02-01 17:06:54 +08:00
|
|
|
使用 `treeData` 把 JSON 数据直接生成树结构。
|
|
|
|
|
2016-08-05 11:47:31 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
The tree structure can be populated using `treeData` property. This is a quick and easy way to provide the tree content.
|
|
|
|
|
|
|
|
|
2017-01-19 15:19:03 +08:00
|
|
|
````__react
|
2016-02-01 17:06:54 +08:00
|
|
|
import { TreeSelect } from 'antd';
|
|
|
|
|
|
|
|
const treeData = [{
|
2016-08-05 11:47:31 +08:00
|
|
|
label: 'Node1',
|
2016-02-16 14:07:09 +08:00
|
|
|
value: '0-0',
|
|
|
|
key: '0-0',
|
|
|
|
children: [{
|
2016-08-05 11:47:31 +08:00
|
|
|
label: 'Child Node1',
|
2016-02-16 14:07:09 +08:00
|
|
|
value: '0-0-1',
|
|
|
|
key: '0-0-1',
|
2016-02-01 17:06:54 +08:00
|
|
|
}, {
|
2016-08-05 11:47:31 +08:00
|
|
|
label: 'Child Node2',
|
2016-02-16 14:07:09 +08:00
|
|
|
value: '0-0-2',
|
|
|
|
key: '0-0-2',
|
2016-02-01 17:06:54 +08:00
|
|
|
}],
|
|
|
|
}, {
|
2016-08-05 11:47:31 +08:00
|
|
|
label: 'Node2',
|
2016-02-16 14:07:09 +08:00
|
|
|
value: '0-1',
|
|
|
|
key: '0-1',
|
2016-02-01 17:06:54 +08:00
|
|
|
}];
|
|
|
|
|
|
|
|
const Demo = React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
2016-10-15 15:28:55 +08:00
|
|
|
value: undefined,
|
2016-02-01 17:06:54 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
onChange(value) {
|
|
|
|
console.log(arguments);
|
|
|
|
this.setState({ value });
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return (
|
2016-10-14 16:17:26 +08:00
|
|
|
<TreeSelect
|
|
|
|
style={{ width: 300 }}
|
2016-02-01 17:06:54 +08:00
|
|
|
value={this.state.value}
|
2016-02-29 16:52:53 +08:00
|
|
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
2016-02-01 17:06:54 +08:00
|
|
|
treeData={treeData}
|
2016-08-05 11:47:31 +08:00
|
|
|
placeholder="Please select"
|
2016-02-01 17:06:54 +08:00
|
|
|
treeDefaultExpandAll
|
2016-06-06 13:54:10 +08:00
|
|
|
onChange={this.onChange}
|
|
|
|
/>
|
2016-02-01 17:06:54 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
ReactDOM.render(<Demo />, mountNode);
|
|
|
|
````
|