我不断收到此错误“ TypeError:无法读取未定义的属性'some'”

时间:2018-07-05 20:26:54

标签: javascript reactjs debugging

我在其中使用了一些功能:

<span className={`icon-eye${
  moviesWatched.some(watch => watch.id === movie.id)
    ? "-blocked"
    : ""
  }`}
  onClick={() => handleChange(movie)}
/>

这是电影里面的内容观看状态:

0:{…}
id:399248

这是movieWatched获得值的方式:

handleChange= (movie) => {
  this.setState({toggleWatched:!this.state.toggleWatched}, () => this.Toggling())

  const { moviesWatched } = this.state;
  const { id } = movie;
  const _movie ={id};

  if(!moviesWatched.find(watch => watch.id === movie.id)){
    return this.setState({moviesWatched:[...moviesWatched,_movie]})
  }

  const WatchedList = moviesWatched.filter(watch => watch.id !== _movie.id)
  this.setState({moviesWatched:WatchedList})
}

为什么在那里,错误:

  

TypeError:无法读取未定义的属性“ some”

即使强硬的moviesWatched也不是undefined吗?

0 个答案:

没有答案