简体   繁体   English

当我 select 一个复选框时,如何禁用 ngfor 中的所有其他复选框?

[英]How to disable all other checkboxes inside ngfor when I select a checkbox?

I have list of item inside table for each item I'm enabling a checkbox to edit and delete values.对于每个项目,我都有一个项目列表,我启用了一个复选框来编辑和删除值。 But I can select only 1 checkbox at time when selected others should be disabled.但是我可以 select 在选择其他应禁用时仅 1 个复选框。

<tr *ngFor="let lists of resObj;let i = index">
              <td>
                <label class="check-box-block">
                  <input type="checkbox" (change)="selectBox($event, lists, lists.id,i)" id="checkBox"
                    [disabled]="chk" />
                  <span class="checkmark"></span>
                </label>
              </td>
</tr>

selectBox(event,list, id, i)
{
 if (event.target.checked) {
      this.chk = true;
      this.checkedArray.push(list);
    } else {
      this.chk = false;
      const newArr = this.checkedArray.filter(item => item !== list);
      this.checkedArray = newArr;
    }
  }
}

you can use a variable "select" and use some like您可以使用变量“选择”并使用一些类似

<input type="checkbox" [checked]="select==i" (change)="select=select==i?-1:i">

NOTE: I don't understand that "selected others should be disabled " (I suppose you want to say unchecked )注意:我不明白“选择的其他人应该被禁用”(我想你想说unchecked

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我 Select 一个复选框时检查其他复选框 - 不是“全选”复选框 - Checking Other Checkboxes when I Select a Checkbox - Not a “Select All” Checkbox 当组中的一个复选框被选中时,禁用并取消选中所有其他复选框 - When one checkbox is checked in a group, disable & uncheck all other checkboxes 如果我选择第一个复选框,则禁用所有剩余的复选框 - If I select first checkbox then disable all remaining checkboxes 如何通过勾选当前部分内的复选框来勾选其他部分的所有复选框? - How do I tick all checkboxes of the other sections by ticking a checkbox found inside the current section? 如果 select 每天取消选中所有其他复选框(复选框) - Unselect all other checkboxes if select daily (checkbox) 选中“所有”复选框时如何取消选择相关复选框,而选中任何相关复选框时如何取消选择“所有”复选框? - How can I de-select related checkboxes when checking “All” checkbox and de-select “All” checkbox when checking any of the related checkboxes? 如果选中另一个复选框,如何启用/禁用复选框? - How do I enable/disable checkboxes when another checkbox is selected? 禁用除最后一个之外的所有先前复选框,启用其他复选框 - Disable all previous checkboxes except last one, enable preceding checkbox when other enabled 选中一个父复选框时禁用所有其他顶级复选框 - Disable all other top level checkboxes when one parent checkbox is selected 如果选中其他复选框,则禁用复选框 - disable checkbox if other checkboxes is checked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM