我通过将我的文本转换为小写并将其索引与 -1 进行比较来进行比较,以便对 ReactJS
中的特定字段具有一些值,但我在 JavaScript 中遇到此错误控制台:
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 的评论是正确答案:
如果 title 是一个字符串,在 toLowerCase() 之前使用 toString():
return episode.title.toString().toLowerCase().indexOf(props.filterText.toString().toLowerCase()) > -1;
关于javascript - ReactJS toLowerCase 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35248292/