Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
Reactjs 删除多个项目_Reactjs - Fatal编程技术网

Reactjs 删除多个项目

Reactjs 删除多个项目,reactjs,Reactjs,我有一个可以通过按下按钮删除的项目列表,如所附的屏幕截图所示。 第一次删除任何项目都可以正常工作,但是当我尝试删除另一个项目时,它将无法工作,因为组件从先前删除的项目接收数据 这是我的代码: 父组件 onDeleteClick(config, e) { // it removes the item at the first time // on the second try the received config parameter is the same as before th

我有一个可以通过按下按钮删除的项目列表,如所附的屏幕截图所示。

第一次删除任何项目都可以正常工作,但是当我尝试删除另一个项目时,它将无法工作,因为组件从先前删除的项目接收数据

这是我的代码:
父组件

onDeleteClick(config, e) {
  // it removes the item at the first time
  // on the second try the received config parameter is the same as before
  this.props.deleteConfigAction(config.configId)
  .then(res => {
    ...
  })
  .catch(err => {
    console.log(err)
  })
}

<Flexbox  marginTop='20px' flexDirection='column'>
  {this.state.configurations.map((config, index) => {
    let boundDeleteClick = this.onDeleteClick.bind(this, config);
    return (
      <ConfigCardView
        key={`item-${index}`}
        handleRemove={boundDeleteClick}/>
    )
  })}
</Flexbox>
我不知道我错过了什么


更新
我已通过在删除项目后更新
配置
状态属性进行了修复:

  this.props.deleteConfigAction(config.configId)
  .then(res => {
    ...
    this.setState({configurations: newData})
  })

我发现这个问题。。。删除项目后,我没有从状态更新
配置。我将此保留为打开状态,因为有人可能会使用此代码结构来实现相同的目标。。。
  this.props.deleteConfigAction(config.configId)
  .then(res => {
    ...
    this.setState({configurations: newData})
  })