简体   繁体   English

错误类型错误:keyword.toLowerCase 不是 function。(在“keyword.toLowerCase()”中,“keyword.toLowerCase”未定义)

[英]ERROR TypeError: keyword.toLowerCase is not a function. (In 'keyword.toLowerCase()', 'keyword.toLowerCase' is undefined)

How can i fix this error which says that ERROR TypeError: keyword.toLowerCase is not a function. (In 'keyword.toLowerCase()', 'keyword.toLowerCase' is undefined) i am building a search user function using js filter in rn, so i am converting the searched keyword to lowercase but now i am facing this error how can i fix it?我如何解决这个错误,它说 ERROR TypeError: keyword.toLowerCase is not a function. (In 'keyword.toLowerCase()', 'keyword.toLowerCase' is undefined) 我正在使用 rn 中的 js 过滤器构建搜索用户 function ,所以我将搜索到的关键字转换为小写,但现在我遇到了这个错误,我该如何解决? what did i do wrong?我做错了什么?

i tried to use ToString method before lowercase method but it didn't works in my case, Can anyone can tell, Where i am wrong?我尝试在小写方法之前使用 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

The TextInput should be like below. TextInput 应该如下所示。 change onChangeText instead of onChange更改onChangeText而不是onChange

<TextInput placeholder='Search'
   style={styles.searchbar}
   onChangeText={(text) => setKeyword(text)}
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM