Skip to content

Commit 91348ac

Browse files
author
jeromeZhang
committed
feat(easyselect): custom lazy loading
1 parent 5a31c1f commit 91348ac

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/components/easy-select/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ class EasySelect extends React.Component<any, any> {
2323

2424
onSearch = (str: any) => {
2525
const { clearValueRequest = false, autoValue } = this.props;
26-
if (!clearValueRequest && !str) { // 默认清空展示上次的数据
26+
if (!clearValueRequest && !str) {
27+
// 默认清空展示上次的数据
2728
this.setState({ dataSource: this.state.dataSource })
28-
} else if (clearValueRequest && !str) { // 此时清空展示最初的数据, 进行初始化的请求,参数传入autoValue
29+
} else if (clearValueRequest && !str) {
30+
// 此时清空展示最初的数据, 进行初始化的请求,参数传入autoValue
2931
this.getDataSource(autoValue);
30-
} else { // 正常搜索函数,特殊处理防抖
32+
} else {
33+
// 正常搜索函数,特殊处理防抖
3134
debounce(() => this.getDataSource(str), 300)();
3235
}
3336
}
3437

3538
lazyDataSource = (data: any) => {
3639
const { scrollPage = 1 } = this.state;
37-
if (data.length > (scrollPage * 100)) {
40+
const { isLazy = true } = this.props;
41+
if (data.length > (scrollPage * 100) && isLazy) {
3842
this.setState({
3943
dataSource: data.slice(0, scrollPage * 100) || [],
4044
allData: data
@@ -81,8 +85,8 @@ class EasySelect extends React.Component<any, any> {
8185
onSearch={ servise && !filterLocal ? this.onSearch : null }
8286
filterOption={ !filterLocal ? null : (input, option) =>
8387
// 兼容数字和字符串等模糊查询
84-
option.props.children.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
85-
option.props.value.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0
88+
option.props?.children?.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
89+
option.props?.value?.toString().toLowerCase().indexOf(input.toLowerCase()) >= 0
8690
}
8791
onPopupScroll={this.companyScroll}
8892
{ ...others }

src/stories/easySelect.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ const propDefinitions = [
6767
required: false,
6868
description: <div className="strory-dt_easy_select_divDesc">清空当前选项是否执行请求(默认清空当前选项不进行服务端请求).</div>,
6969
defaultValue: 'false'
70+
},
71+
{
72+
property: 'isLazy',
73+
propType: 'boolean',
74+
required: false,
75+
description: <div className="strory-dt_easy_select_divDesc">数据超过一百是否懒加载,默认为true</div>,
76+
defaultValue: 'true'
7077
}]
7178
stories.add('EasySelect', () => (
7279
<div className='story_wrapper'>

0 commit comments

Comments
 (0)