Select the multi-box in the table and add this item to the array, but if you click not to select it, it will also be added. How to solve the problem?

problem description

Select the multi-box in the

table and add this item to the array, but if you click not to select it, it will also be added. How to solve

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

< el-checkbox @ change= "getRow (scope.row)" VMI if = "scope.row.platformUsername" > < / el-checkbox >

getRow:function (row) {

   this.nextDataArr.push({"platfromLogo":row.platfromLogo,"platformZid":row.platformZid,"userPlat formZid":row.userPlatnameWithZid[0].userPlatformZid})

   },

what result do you expect? What is the error message actually seen?

error: I click, select, add data, and click not to select the array again will also add data

Mar.28,2021


v-model will help you maintain a list, that won't repeat push.


The js judgment array used in

defines a new array
getRow:function (row) {

because there is an object in my array.
if (this.nextDataArrry.indexOf(row.userPlatnameWithZid[0].userPlatformZid) === -1) {
     this.nextDataArrry.push(row.userPlatnameWithZid[0].userPlatformZid)this.nextDataArr.push({"platfromLogo":row.platfromLogo,"platformZid":row.platformZid,"userPlatformZid":row.userPlatnameWithZid[0].userPlatformZid})
        } else {
            this.nextDataArrry.splice(this.nextDataArrry.indexOf(row.userPlatnameWithZid[0].userPlatformZid), 1)
            this.nextDataArr.splice(this.nextDataArrry.indexOf(row.userPlatnameWithZid[0].userPlatformZid), 1)
        }
        console.log(this.nextDataArrry)
        console.log(this.nextDataArr)
   },

this is a solution.

Menu