TypeError:无法读取未定义的属性“ toLowerCase”,此错误总是重新运行

时间:2018-12-28 01:12:10

标签: javascript reactjs

我正在尝试设置文本过滤器以在我的react和get error中添加搜索功能无法读取未定义的属性'toLowerCase' 这里的代码可能有帮助

我的代码:

import React, { Component } from "react";
import CardList from "./cardList";
import { robots } from "./robots";
import SearchBox from "./searchBox";

   class App extends Component {
   constructor() {
    super();
          this.state = {
         robots: robots,
          searchfield:''
        }
       }

   onSearchChange = (event) => {
        this.setState({searchfield: event.target.value})
      }

  render() {
    const filteredRobots = this.state.robots.filter(robots =>{
        return robots.mame.toLowerCase().includes(
    this.state.searchfield.toLowerCase());

     });
     return (
      <div className="tc">
         <h1> robots Friends </h1>
        <SearchBox searchChange={this.onSearchChange}/>
        <CardList robots={filteredRobots}/>
       </div>
    );
  }
}
export default App;

1 个答案:

答案 0 :(得分:0)

包含了CSS文件。 我发现一个空属性border-color:;会导致这种消息。

请参阅:https://stackoverflow.com/a/57772350/1235724