angular-zorro nzShowCheckbox需要点击两次才能选中 、 Indeterminate的含义

本文探讨了nzShowCheckbox组件需要点击两次才能选中的问题,并解释了Indeterminate状态的作用及其判断逻辑。通过示例代码说明如何实现全选、单选及Indeterminate状态的更新。

一、nzShowCheckbox需要点击两次才能选中

 

原因:

data.checked的真假值切换已经自动完成了,不应该再次切换

 

二、Indeterminate的含义

当indeterminate的值为真时,强制将选中状态变为 - (只影响界面显示,不影响数据)

indeterminate何时为真?

除以下两个状态之外

(1)所有的单选框选中

(2)所有的单选框未选中

即:部分选中

 

 

 

附:

itemList是列表数据

  checkAll() {
    if(this.allChecked_table){
      this.itemList.forEach(i=>i.checked=true)
    }else{
      this.itemList.forEach(i=>i.checked=false)
    }
    this.ensure_state_indeterminate_table()
  }

  checkOne() {
    this.ensure_state_indeterminate_table()
    this.ensure_state_allChecked_table()
  }

  ensure_state_indeterminate_table(){
    let is_all_check = this.itemList.every(i=>i.checked==true)
    let is_all_not_check = this.itemList.every(i=> (i.checked==false || i.checked==undefined || i.checked==null))
    if(is_all_check || is_all_not_check){
      this.indeterminate_table = false
    }else{
      this.indeterminate_table = true
    }
  }

  ensure_state_allChecked_table(){
    let is_all_not_check = this.itemList.every(i=> (i.checked==false || i.checked==undefined || i.checked==null))
    if(is_all_not_check) {
      this.allChecked_table = false;
    }else{
      this.allChecked_table = true;
    }
  }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值