【发布时间】:2022-01-12 23:11:16
【问题描述】:
我的搜索栏过滤器出现问题。例如,我希望可以在我的平面列表中搜索比特币或 btc 的名称。但是,它只接收第一个(比特币),当我输入(btc)时,平面列表没有改变。我注意到通过切换变量 item.CoinInfo.FullName 或 item.CoinInfo.Name 它只会选择首先列出的内容。
search = searchText => {
this.setState({searchText: searchText});
// searchText empty, reset filtered array
if (!searchText) {
this.setState({filteredCryptos: []});
return;
}
let filteredCryptos = this.state.cryptos.filter(function (item) {
// Defaults to empty string
let name = item.CoinInfo
? item.CoinInfo.FullName || item.CoinInfo.Name || ''
: '';
// If no such property, skip
if (!name) {
return false;
}
// Change to both to lowercase, as you want to match 'bitcoin' and 'Bitcoin'
return name.toLowerCase().includes(searchText.toLowerCase());
});
this.setState({filteredCryptos: filteredCryptos});
};
【问题讨论】:
标签: react-native search filter