0

I have multiple delete option in my app and it does delete items from database but the issue is in front-end. Somehow I can't splice right items from list

Demo

one

As you can see I deleted items 2 and 3 but item 1 removed from list.

Code

commented

toggleSelection(row) {
    const myIds = this.multipleSelection.map((row) => row.id);
    this.$confirm('This will permanently delete the items. Continue?', 'Warning', {
        confirmButtonText: 'Yes',
        cancelButtonText: 'Cancel',
        type: 'warning',
        center: true
    }).then(() => {
        axios.post('/api/wishlist/destroyMultiple/', {ids: myIds}).then((res) => {
            this.$message({
                showClose: true,
                type: 'success',
                message: res.data.success
            });
            this.wishlist.splice(this.wishlist.indexOf(row), 1)  // issue comes from here
        })
        .catch((err) => {
            this.$message({
                showClose: true,
                type: 'info',
                message: err
            });
        });
    }).catch(() => {
        this.$message({
            showClose: true,
            type: 'info',
            message: 'Delete canceled'
        });
    });
},

Any idea?

3
  • What is the input value (row) of the toggleSelection function? a single row? or all selected rows? or what? Commented Jul 4, 2020 at 3:36
  • @MuhammadVakili undefined Commented Jul 4, 2020 at 3:40
  • @MuhammadVakili source of this function Commented Jul 4, 2020 at 3:42

1 Answer 1

1

So, It seems that you're trying to access the index of undefined and splice it right here:

this.wishlist.splice(this.wishlist.indexOf(row), 1) 

The code above will remove the last element of the array. Let's try this one:

this.multipleSelection.forEach(x => this.wishlist.splice(this.wishlist.indexOf(x),1))
Sign up to request clarification or add additional context in comments.

1 Comment

ReferenceError: a is not defined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.