我如何修复这个错误,说错误TypeError:keyword.toLowerCase不是一个函数。(在'keyword.toLowerCase()'中,'keyword.toLowerCase'未定义)我正在rn中使用js filter构建一个搜索用户函数,所以我将搜索到的关键字转换为小写,但现在我面临这个错误,我该如何修复它?我做错了什么?
我试着在小写方法之前使用ToString方法,但它在我的情况下不起作用,有人能告诉我,我哪里错了吗?
import { StyleSheet, Text, View } from 'react-native'
import React, { useState } from 'react'
import { ScrollView, TextInput } from 'react-native-gesture-handler'
import { Ionicons } from '@expo/vector-icons';
import { formHead } from '../../CommonCss/FormCss';
import ChatCard from '../../Cards/ChatCard';
const MainChat = ({ navigation }) => {
const chats = [
// here is raw data of users i remove it bcs than code will hard to read the data was too long
]
const [keyword, setKeyword] = useState('')
return (
<ScrollView style={styles.container}>
<Ionicons name="arrow-back" size={24} color="grey" style={styles.backbtn}
onPress={() => navigation.navigate("mainpage")}
/>
<View style={styles.searchSection}>
<Text style={formHead}>Your Chats</Text>
<TextInput placeholder='Search'
style={styles.searchbar}
onChange={(text) => setKeyword(text)}
/>
</View>
<View style={styles.ChatSection}>
{
chats.filter(
(chat) => {
if (keyword == '') {
return chat
}
else if (
chat.username.
toLowerCase().includes
(keyword.toLowerCase())
) {
return chat
}
}
).map((chat) => {
return <ChatCard key={chat.username} chat={chat} />
})
}
</View>
</ScrollView>
)
}
export default MainChat
1条答案
按热度按时间knpiaxh11#
TextInput应如下所示。更改onChangeText而不是onChange