【发布时间】:2021-01-18 15:19:15
【问题描述】:
我使用 react-native-searchable-dropdown 库,但如果用户在项目数组中写入字符串,我会收到白屏。 如何不添加任何结果文本(或创建缺失选项的最佳选项按钮)?
【问题讨论】:
标签: react-native searchable-dropdown
我使用 react-native-searchable-dropdown 库,但如果用户在项目数组中写入字符串,我会收到白屏。 如何不添加任何结果文本(或创建缺失选项的最佳选项按钮)?
【问题讨论】:
标签: react-native searchable-dropdown
如果您使用 flatlist 列出所有数据。有一个叫 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>
);
};
在函数中
空组件
你可以为所欲为
【讨论】: