ReactJS toLowerCase不是一个函数 [英] ReactJS toLowerCase is not a function

查看:382
本文介绍了ReactJS toLowerCase不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过将我的文本转换为小写并将其索引与-1进行比较来进行比较,以便为 ReactJS 中的特定字段赋予一些值,但是我我在JavaScript控制台中收到此错误:

I am doing a comparison by converting my text to lowercase and comparing its index to -1, in order to have some value to the particular field in ReactJS, but I am getting this error in JavaScript console:


未捕获TypeError:props.filterText.toLowerCase不是函数

Uncaught TypeError: props.filterText.toLowerCase is not a function



var props = this.props;
var rows = this.props.episodes
    .filter(function(episode){
        return episode.title.toLowerCase().indexOf(props.filterText.toLowerCase()) > -1;
    })
    .map(function(episode){
       return <EpisodeRow key={episode.title} episode={episode}/>
    });


推荐答案

看起来Chris的评论是正确答案:

Looks like Chris's comment is the correct answer:

如果 title 是一个字符串,请在toLowerCase()之前使用 toString()

If title is a string, use toString() before toLowerCase():

return episode.title.toString().toLowerCase().indexOf(props.filterText.toString().toLowerCase()) > -1;

这篇关于ReactJS toLowerCase不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆