没有结果 react-native-searchable-dropdown
no result react-native-searchable-dropdown
我使用的是 react-native-searchable-dropdown 库,但如果用户写入的字符串不在项目数组中,我会收到白屏。
我如何才能添加无结果文本(或其创建缺失选项的最佳选项按钮)?
如果您使用平面列表列出所有数据。有一个道具叫做 ListEmptyComponent
import React from 'react',
import {FlatList, Button, Text} from 'react-native',
const emptyComponent = () => {
return(
<Text>Search result not found</Text>
<Button title='Do Something'/>
)
};
<FlatList
istEmptyComponent={emptyComponent}
/>
如果找不到搜索结果,将显示此内容。
实际上这是可行的,只是我需要添加一些细节,它需要更改相同的可搜索下拉文件:
const oldSupport = [
{ key: 'keyboardShouldPersistTaps', val: 'always' },
{ key: 'nestedScrollEnabled', val : false },
{ key: 'style', val : { ...this.props.itemsContainerStyle } },
{ key: 'data', val : this.state.listItems },
{ key: 'keyExtractor', val : (item, index) => index.toString() },
{ key: 'renderItem', val : ({ item, index }) => this.renderItems(item, index) },
{ key: 'ListEmptyComponent', val : () =>this.emptyComponent()}
I added :
{ key: 'ListEmptyComponent', val : () =>this.emptyComponent()}
之后我只是添加
emptyComponent = () => {
return(
<View>
<Text>Search result not found</Text>
<Button title='Do Something'/>
</View>
);
};
并在函数中
emptyComponent
你可以随心所欲
我使用的是 react-native-searchable-dropdown 库,但如果用户写入的字符串不在项目数组中,我会收到白屏。 我如何才能添加无结果文本(或其创建缺失选项的最佳选项按钮)?
如果您使用平面列表列出所有数据。有一个道具叫做 ListEmptyComponent
import React from 'react',
import {FlatList, Button, Text} from 'react-native',
const emptyComponent = () => {
return(
<Text>Search result not found</Text>
<Button title='Do Something'/>
)
};
<FlatList
istEmptyComponent={emptyComponent}
/>
如果找不到搜索结果,将显示此内容。
实际上这是可行的,只是我需要添加一些细节,它需要更改相同的可搜索下拉文件:
const oldSupport = [
{ key: 'keyboardShouldPersistTaps', val: 'always' },
{ key: 'nestedScrollEnabled', val : false },
{ key: 'style', val : { ...this.props.itemsContainerStyle } },
{ key: 'data', val : this.state.listItems },
{ key: 'keyExtractor', val : (item, index) => index.toString() },
{ key: 'renderItem', val : ({ item, index }) => this.renderItems(item, index) },
{ key: 'ListEmptyComponent', val : () =>this.emptyComponent()}
I added :
{ key: 'ListEmptyComponent', val : () =>this.emptyComponent()}
之后我只是添加
emptyComponent = () => {
return(
<View>
<Text>Search result not found</Text>
<Button title='Do Something'/>
</View>
);
};
并在函数中
emptyComponent
你可以随心所欲