如何使用 reactjs 删除动态 table 中的所有点击行
How to delete all rows on click in a dynamic table using reactjs
目前点击删除按钮一次只能删除一行。但是,我目前的目标是同时删除所有行,但我尝试过的解决方案不起作用。这是当前代码:
const [shop, setShop] = useState([]);
...
const [count, setCount] = useState(0);
...
const handleDelete = (shopsId) => {
const newArr = [...shop];
const index = shop.findIndex((shop) => shop.id === shopsId);
newArr.splice(index, 1);
setShop(newArr);
setCount(count - count)
}
如果我想删除特定行,此方法成功,但我不想这样做,而是删除所有行 ('delete all')。任何帮助将不胜感激。
设为空数组
setShop([ ])
目前点击删除按钮一次只能删除一行。但是,我目前的目标是同时删除所有行,但我尝试过的解决方案不起作用。这是当前代码:
const [shop, setShop] = useState([]);
...
const [count, setCount] = useState(0);
...
const handleDelete = (shopsId) => {
const newArr = [...shop];
const index = shop.findIndex((shop) => shop.id === shopsId);
newArr.splice(index, 1);
setShop(newArr);
setCount(count - count)
}
如果我想删除特定行,此方法成功,但我不想这样做,而是删除所有行 ('delete all')。任何帮助将不胜感激。
设为空数组
setShop([ ])