Delete an element by key from Array

前端 未结 2 1148
猫巷女王i
猫巷女王i 2021-01-26 13:30

I used library react-sortable-hoc for drag and drop element, but the library documentation does not have any actions for delete items. I want to delete, drag and drop item when

2条回答
  •  自闭症患者
    2021-01-26 14:04

    UPDATED:

    Hi there, I figured out what went wrong and made a successful remove event on your application.

    Everything is illustrated with comments at this codesandbox.

    =========

    I modified this one, it should do the required using Array's filter method.

    public onRemove(e: { target: { value: any; }; }) {
        let array = [...this.state.items];
        const intId = parseInt(e.target.value, 10);
        array = array.filter(item => item.id !== intId);
        this.setState({items: array});
    }
    

提交回复
热议问题