页面代码:
但是奇怪的是 我点击按钮 进行全选操作时,选择框并没勾上,哪里有问题?
for="item in itemList" :label="item.name" :key="item.id" :disabled="item.disabled" :checked="item.checked">{{ item.name }}
JS代码:
handleCheckedAllItem() {
this.checkAll = !this.checkAll
console.log(this.checkAll)
for(let index=0;index<this.itemList.length;index++){
let temp= this.itemList[index];
temp.checked = this.checkAll
this.itemList.splice(index, 1, temp); //替换数组中这个元素
}
console.log(this.itemList.length)
console.log(this.itemList)
}
结帖:
首先 没有按照官网那样来的,就是双向绑定的问题 v-for 不能检测到item 中数据的变化,需要用splice 进行替换元素, 说白了就是进栈出栈的问题,这样就行了,如果还是不行 那就像我一样 没有将元素写入group 的 v-model 中 ,注意绑定的v-for 元素的label
for(let index=0;index<this.itemList.length;index++){
let temp= this.itemList[index];
temp.checked = this.checkAll
this.itemList.splice(index, 1, temp); //替换数组中这个元素
this.checkList.push(temp.name) //不能丢!!!!!!!!!!!
}
不知道你这个问题是否已经解决, 如果还没有解决的话: