Skip to content

Commit 13dc5b3

Browse files
author
liyuan-meng
committed
✨[TreeSelect]添加 demo
1 parent bff503e commit 13dc5b3

1 file changed

Lines changed: 171 additions & 0 deletions

File tree

  • src/components/tree-select/demos
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
---
2+
order: 2
3+
title: 多层单选与多选
4+
desc: 与Tree结合的树下拉
5+
---
6+
7+
```jsx
8+
import React from 'react';
9+
import { TreeSelect } from 'cloud-react';
10+
11+
class TreeSelectDemo extends React.Component {
12+
treeData = [
13+
{
14+
id: 11,
15+
name: '禁止删除节点',
16+
pId: 1,
17+
disableRemove: true,
18+
children: [
19+
{
20+
id: 113,
21+
name: '删除三个',
22+
pId: 11,
23+
children: [
24+
{
25+
id: 1131,
26+
name: '禁止删除节点31',
27+
pId: 113,
28+
children: []
29+
},
30+
{
31+
id: 1132,
32+
name: '禁止删除节点32',
33+
pId: 113,
34+
children: [
35+
{
36+
id: 11321,
37+
name: '禁止删除节点321',
38+
pId: 1132,
39+
children: []
40+
}
41+
]
42+
}
43+
]
44+
},
45+
{
46+
id: 114,
47+
name: '禁止删除节点4',
48+
pId: 11,
49+
children: []
50+
}
51+
]
52+
},
53+
{
54+
id: 14,
55+
name: '未分类',
56+
pId: 1,
57+
disableRemove: true,
58+
disableAdd: true,
59+
disableRename: true,
60+
children: []
61+
}
62+
];
63+
64+
constructor(props) {
65+
super(props);
66+
67+
this.state = {
68+
selectedNodes: [
69+
{
70+
id: 11321,
71+
name: '禁止删除节点321',
72+
pId: 1132,
73+
children: []
74+
}
75+
],
76+
confirmNodes: [],
77+
singleNodes: [
78+
{
79+
id: 11321,
80+
name: '禁止删除节点321',
81+
pId: 1132,
82+
children: []
83+
}
84+
]
85+
};
86+
setTimeout(() => {
87+
this.setState({
88+
confirmNodes: [this.treeData[0]]
89+
});
90+
}, 1000);
91+
92+
}
93+
94+
handleChange = (node, selectedNodes) => {
95+
console.log(node, selectedNodes);
96+
97+
this.setState({
98+
selectedNodes
99+
});
100+
};
101+
102+
handleConfirmChange = (node, selectedNodes) => {
103+
console.log(node, selectedNodes);
104+
105+
this.setState({
106+
confirmNodes: selectedNodes
107+
});
108+
};
109+
110+
onOk = (node, selectedNodes) => {
111+
console.log(node, selectedNodes);
112+
113+
this.setState({
114+
confirmNodes: selectedNodes
115+
});
116+
};
117+
118+
onChangeSingle = (node, selectedNodes) => {
119+
console.log(node, selectedNodes);
120+
121+
this.setState({
122+
singleNodes: selectedNodes
123+
});
124+
};
125+
126+
render() {
127+
return (
128+
<div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
129+
<div>
130+
<h5>单选</h5>
131+
<TreeSelect
132+
searchable
133+
searchInBox
134+
showPath
135+
allowClear
136+
type="single"
137+
isUnfold
138+
containParentNode
139+
placeholder="选择一个选项"
140+
style={{ width: 420, maxWidth: 420 }}
141+
dropdownStyle={{ maxWidth: 420 }}
142+
dataSource={this.treeData}
143+
value={this.state.singleNodes}
144+
onChange={this.onChangeSingle}
145+
/>
146+
</div>
147+
<div>
148+
<h5>多选</h5>
149+
<TreeSelect
150+
searchable
151+
searchInBox
152+
allowClear
153+
showPath
154+
type="multiple"
155+
isUnfold
156+
containParentNode
157+
placeholder="选择一个选项"
158+
style={{ width: 420, maxWidth: 420 }}
159+
dropdownStyle={{ maxWidth: 420 }}
160+
dataSource={this.treeData}
161+
value={this.state.selectedNodes}
162+
onChange={this.handleChange}
163+
/>
164+
</div>
165+
</div>
166+
);
167+
}
168+
}
169+
170+
export default TreeSelectDemo;
171+
```

0 commit comments

Comments
 (0)