reactjs - 如何在 react-bootstrap-table2 (React.js) 中添加特定于行的操作按钮
问题描述
我正在尝试向使用 react-bootstrap-table2 呈现的表的每一行添加一个删除按钮。我已按类别对数据进行排序并放置在我当地的州
state = {
data: [
{
products: [
{
name: "Product 1",
price: "200"
},
{
name: "Product 2",
price: "300"
},
...
]
},
...
}
并为每个对象呈现一个单独的表,this.state.data
并使用来自相应对象的 products 数组中的数据填充this.state.data.map((category, index) => ..)
。我还设置了每个表的' 对象id
的索引以匹配它们被渲染的位置。this.state.data
但我挣扎的是,我想为每一行添加一个删除按钮;搜索后,我发现了为我们提供的formatter
属性,但我如何访问该表?所以我可以潜在地使用我的代码:columns
cell, row, rowIndex
id
columns
columns = () => {
...
{
isDummyField: true,
formatter: (cell, row, rowIndex) => {
return <Button
color="primary"
onClick={() => {
console.log (`Product ${rowIndex} of Category ${tableId} deleted`);
}>
Delete Product
</Button>
}
}
}
我不知道如何访问tableId
. 谁能帮我这个?我一直觉得 react-bootstrap-tables 非常令人困惑。
解决方案
我从后端解决了这个问题。基本上我为每个产品添加了一个唯一的 id,然后在按钮onClick=()
中,我简单地使用访问了产品的唯一 idrow.id
推荐阅读
- r - 带有多个触发表达式的 ObserveEvent :知道发生了哪一个
- sql - SQLite 书店:最后的学生和他们订购的所有书籍
- api-platform.com - api platform.com - 不受支持的媒体类型
- javascript - 使用 fetch 从流中读取并创建一个 excel 文件
- python - 为什么在直方图均衡中使用 float 16
- reactjs - React 本地视频不会在生产中加载
- intellij-idea - IDEA - 有没有办法制作组合(合并)动作快捷方式?
- mysql - mySQL中的自动递增字符串
- android - 使用 Mockito 的 Android 中 FirebaseRemoteConfig 的 JUnit 测试用例
- node.js - 无法通过 aws lambda 函数从浏览器下载 base64 图像?