-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathfilter.tsx
108 lines (100 loc) · 3.06 KB
/
filter.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import '../assets/index.less';
import React from 'react';
import TreeSelect, { SHOW_PARENT } from '../src';
import { gData } from './utils/dataUtil';
console.log('TreeData:', gData);
class Demo extends React.Component {
state = {
value: '11',
// value: ['0-0-0-0-value', '0-0-0-1-value', '0-0-0-2-value'],
simpleTreeData: [
{ key: 1, pId: 0, label: 'a', value: 'a' },
{ key: 11, pId: 1, label: 'a12', value: 'a12', disabled: true },
{ key: 111, pId: 11, label: 'a00', value: 'a00', selectable: false },
{ key: 2, pId: 0, label: 'b', value: 'b' },
{ key: 20, pId: 2, label: 'b10', value: 'b10' },
{ key: 21, pId: 2, label: 'b1', value: 'b1' },
{ key: 22, pId: 2, label: 'b12', value: 'b12' },
],
treeDataSimpleMode: {
id: 'key',
rootPId: 0,
},
};
onChange = value => {
const { simpleTreeData } = this.state;
if (value.length === 1) {
// return;
}
console.log('onChange', value, simpleTreeData);
this.setState({ value });
};
onSelect = () => {
// use onChange instead
// console.log(arguments);
};
onDataChange = () => {
const { simpleTreeData } = this.state;
const data = simpleTreeData.slice();
data.forEach(i => {
if (i.key === 11) {
// eslint-disable-next-line no-param-reassign
delete i.disabled;
}
if (i.key === 20) {
// eslint-disable-next-line no-param-reassign
i.disabled = true;
}
});
this.setState({ simpleTreeData: data });
};
render() {
const { value, simpleTreeData, treeDataSimpleMode } = this.state;
return (
<div style={{ margin: 20 }}>
<h2>check select</h2>
<TreeSelect
style={{ width: 300 }}
transitionName="rc-tree-select-dropdown-slide-up"
choiceTransitionName="rc-tree-select-selection__choice-zoom"
// dropdownStyle={{ height: 200, overflow: 'auto' }}
// dropdownPopupAlign={{
// overflow: { adjustY: 0, adjustX: 0 },
// offset: [0, 2],
// }}
placeholder={<i>请下拉选择</i>}
treeLine
maxTagTextLength={10}
value={value}
treeData={gData}
treeNodeFilterProp="title"
treeCheckable
onChange={this.onChange}
onSelect={this.onSelect}
/>
<h2>use treeDataSimpleMode</h2>
<TreeSelect
style={{ width: 300 }}
popupStyle={{ maxHeight: 200, overflow: 'auto' }}
placeholder={<i>请下拉选择</i>}
treeLine
maxTagTextLength={10}
inputValue={null}
value={value}
treeData={simpleTreeData}
treeDefaultExpandAll
treeNodeFilterProp="title"
treeDataSimpleMode={treeDataSimpleMode}
treeCheckable
showCheckedStrategy={SHOW_PARENT}
onChange={this.onChange}
onSelect={this.onSelect}
/>
<button type="button" onClick={this.onDataChange}>
change data
</button>
</div>
);
}
}
export default Demo;