Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用indexOf的javascript搜索不';不使用map()工作_Javascript_Reactjs_Ecmascript 6 - Fatal编程技术网

使用indexOf的javascript搜索不';不使用map()工作

使用indexOf的javascript搜索不';不使用map()工作,javascript,reactjs,ecmascript-6,Javascript,Reactjs,Ecmascript 6,尝试使用react隐藏和显示列表,但失败 handleChange = e => { const { list } = this.state; if (e.target.value !== "") { this.setState({ list: list.map(o => ({ name: o.name, hide: !o.name.indexOf(e.target.value) > -1

尝试使用react隐藏和显示列表,但失败

handleChange = e => {
    const { list } = this.state;

    if (e.target.value !== "") {
      this.setState({
        list: list.map(o => ({
          name: o.name,
          hide: !o.name.indexOf(e.target.value) > -1
        }))
      })
    } else {
      this.setState({
        list: list.map(o => ({
          name: o.name,
          hide: false
        }))
      });
    }
  };

有什么线索吗

让我解释一下你做错了什么

隐藏:!o、 name.indexOf(e.target.value)>-1

在上面的代码中,indexOf值将被返回(可能是某个数字),然后返回false,因为
操作员

您试图将BOOL值与整数-1进行比较,该整数将明显返回false

用括号括起您的病情,然后放入
如下所示

隐藏:!(o.name.indexOf(e.target.value)>-1)

或使用以下条件

hide:o.name.indexOf(e.target.value)==-1

它会起作用的