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
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>
ConfigCardView
零件:
...
<button onClick={(e, config) => this.props.handleRemove()}>Delete</button>
...
我无法弄清楚我错过了什么......
更新
我已通过configurations
在删除项目后更新 state 属性来修复:
this.props.deleteConfigAction(config.configId)
.then(res => {
...
this.setState({configurations: newData})
})
解决方案
推荐阅读
- object-detection - 找到信息有限的质心边界框
- java - 是否可以用一个 replaceAll 来编写它?
- c# - 如何以日期格式显示 EditorFor 模型值
- python - Pyplot Quiver 函数中的奇怪行为
- node.js - 在 express 上搜索 mongodb atlas
- azure-blob-storage - BizTalk BlobStorageAdapter - 将 Blob 元数据提升为 BizTalk 属性
- certificate - 连接热点时使用什么机制向客户端发送证书
- reactjs - 为表单创建主挂钩
- c++ - 删除用一对两个整数填充的向量中的重复项
- python - 如何在kivy中使用boxlayout仅包含代码的特定部分