1.全选 cheakAll: false
改变全选状态,为true时全部打勾(遍历单选)
getAll(){
this.shopList.forEach((item ,index)=> {
item.check = this.cheackAll
//check为单选状态
})
}
2.多选,单选
① var n = 当前shopList中的check值为ture的个数
② if(选中的长度 == 全选的长度),全选为true,否则为false
changAll(){
第一种方式
//选中状态 filter( ) ,返回满足条件的值
var n = this.shopList.filter(function(item){
return item.check == true
}).length
n == this.shopList.length ? this.checkAll = true : this.checkAll = false
第二种方式
this.checkAll = this.shopList.every(function(item){
return item.check
})
}
every() 方法(布尔型)用于检测数组所有元素是否都符合指定条件(通过函数提供)。满足返回true,否则返回false。一假为假,全真为真。
some() 方法用于检测数组中的元素是否满足指定条件(函数提供)。一真为真,全假为假。