ReactJS toLowerCase不是一个函数

Max*_*rld 7 html javascript reactjs reactjs-native

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

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

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}/>
    });
Run Code Online (Sandbox Code Playgroud)

The*_*Guy 8

看起来克里斯的评论是正确的答案:

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

return episode.title.toString().toLowerCase().indexOf(props.filterText.toString().toLowerCase()) > -1;
Run Code Online (Sandbox Code Playgroud)