简体   繁体   中英

Push object to array of objects on click

I have a vue.js app that has objects being rendered in a single list with two columns as shown below: 在此处输入图像描述

When I click on the "X" on the object, I get the following return: 在此处输入图像描述

The method is shown below:

remove(x) {
    console.log(this.$data.list.selected[x]);
    console.log(this.$data.list.available);
    console.log(x);
},

The this.$data.list.selected[x] is the object in the left column, and the array of objects is in this.$data.list.available .

What would be the best way for me to remove the object inside my method and then push it to the end of the array in this.$data.list.available ?

You could splice the item to remove it from this.$data.list.selected[] , and push it into this.$data.list.available[] :

this.$data.list.available.push(...this.$data.list.selected.splice(x, 1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM