【问题标题】:When checkbox is uncheck, I want to return all my list当复选框未选中时,我想返回我的所有列表
【发布时间】:2021-11-05 01:50:14
【问题描述】:

当我取消选中我的文本框时,它不会返回 selectedItemsList .希望你能理解我的问题。

 changeSelection() {
            this.checkedIDs = []
            this.selectedItemsList = this.DisplayProductList.filter((value, index) => {
              if (value.isChecked == true) {
               
                return value.isChecked
              }
            
                else{
                this.selectedItemsList = this.ProductData;
              
              }
             
            });
          
            this.router.navigate(['pipeline/cluster/policies'])
            this.sendclusteridApi()
          }

【问题讨论】:

    标签: arrays angular checkbox boolean boolean-expression


    【解决方案1】:
                 if (value.isChecked == false){
                    this.selectedItemsList = this.ProductData;
                  }
                    else{
                    this.selectedItemsList = this.ProductData;
                  
                  }
    

    你在这里肯定错了。在ifelse 条件下做同样的事情。

    【讨论】:

    • 您好,感谢您的回复,是的,我不小心重复了。如果 value.ischecked == false 则返回 value.ischecked,否则返回 selectedItems。这就是我要找的
    【解决方案2】:

    根据需要更改此代码,遵循相同的结构:

    HTML:

    <mat-checkbox (click)="showData()" (checked)="(isChecked)" (change)="isChecked = !isChecked"></mat-checkbox>
    
    <!-- below part only to visually see the change  -->
    <div *ngFor="let elem of displayedItems">
        <p>{{ elem.name }}</p>
    </div>
    

    打字稿:

    displayedItems = [];
    selectedItemsList = [
            {
                item1: 'hello',
                name: 'item1',
            },
            {
                item2: 'hello',
                name: 'item3',
            },
            {
                item3: 'hello',
                name: 'item3',
            },
        ];
    
    showData() {
            if (this.isChecked === false) {
                this.displayedItems = this.selectedItemsList;
            } else {
                this.displayedItems = [];
            }
        }
    
    

    【讨论】:

    • 感谢您的回复,我解决了问题,我需要传递事件。我做到了。它类似于您的解决方案
    猜你喜欢
    • 1970-01-01
    • 2011-09-30
    • 2016-10-01
    • 2013-05-08
    • 1970-01-01
    • 2022-06-10
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多