在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 表格中多選框,選中一個就往數(shù)組里面添加這一條的數(shù)據(jù),但是再點擊不選中,也會添加,

表格中多選框,選中一個就往數(shù)組里面添加這一條的數(shù)據(jù),但是再點擊不選中,也會添加,如何解決

問題描述

表格中多選框,選中一個就往數(shù)組里面添加這一條的數(shù)據(jù),但是再點擊不選中,也會添加,如何解決

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

相關(guān)代碼

// 請把代碼文本粘貼到下方(請勿用圖片代替代碼)

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

getRow:function(row){

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

   },

你期待的結(jié)果是什么?實際看到的錯誤信息又是什么?

錯誤:我點一下,選中,添加數(shù)據(jù),再次點擊不選中數(shù)組里面也會添加數(shù)據(jù)

回答
編輯回答
壞脾滊

v-model 會幫你維護(hù)一個 list,不會重復(fù) push...

2017年5月14日 03:56
編輯回答
賤人曾

v-model?

2017年8月3日 04:04
編輯回答
萌二代

用的js的判斷數(shù)組 由于我的數(shù)組里面是一個對象所有就定義了一個新的數(shù)組
getRow:function(row){

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)
   },

這樣算是解決了。

2017年6月28日 00:05