vue 复选框

checkedAll (index) { // 全选按钮

let list = this.list.checkBoxConditions[index].conditionItems

if (this.checked[index] === true) { // 实现全选

list.forEach(item => {

item.isChecked = false

})

} else {

list.forEach(item => {

item.isChecked = true

})

}

},

checkedSingle (index, subindex) { // 单选按钮 决定全选按钮

let num = 0 // 除了当前选项,其他选中的次数

let flag = false // 其他选项是否都选中

for (let j = 0; j < this.list.checkBoxConditions[index].conditionItems.length; j++) {

if (j === subindex) { // 当前选择为false为选中,正好相反,在后续做处理

continue

}

if (this.list.checkBoxConditions[index].conditionItems[j].isChecked === true) { // 记录剩余的是否选中

num++

}

if (num === this.list.checkBoxConditions[index].conditionItems.length - 1) {

flag = true

} else {

flag = false

}

}

if (this.list.checkBoxConditions[index].conditionItems[subindex].isChecked === false && flag === true) { // 选中的select为false和剩余的为true则为true

this.checked[index] = true

} else {

this.checked[index] = false

}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章