ngx-datatable,元素不可见后呈现取消选中项

ngx-datatable, uncheck item is rendered after the element is not visible

我想做的是为我的 ngx-datatable

分配我可以拥有的托运项目数量限制

这是我正在使用的代码:

onSelect({ selected, event }) {
    if (this.checkboxLimit <= 0 ) { //THIS IS WORKING FINE
      this.selected.splice(0, this.selected.length);
      this.selected.push(...selected);
      this.checkedItems = selected;
      this.numberOfSelectedCheckboxes.emit(this.checkedItems.length);
      return;
    }

    if (selected.length === 0 ) {  //THIS IS WORKING FINE
      this.selected = [];
      this.checkedItems = [];
      this.lastSelection = [];
      this.numberOfSelectedCheckboxes.emit(0);
      return;
    } else if (selected.length === 1 ) { //THIS IS WORKING FINE
      this.selected = [...selected];
      this.checkedItems = [...selected];
      this.lastSelection = [...selected];
      this.numberOfSelectedCheckboxes.emit(1);
      return;
    } if(selected.length === this.checkboxLimit + 1) {  //THIS IS NOT WORKING!
      this.checkedItems = [...this.lastSelection];
      this.selected = [...this.lastSelection];
      this.tableOffset = 0;

      console.log('Uncheck the element!!!!');
      return;
    } else {  //THIS IS WORKING FINE
        if(selected.length > this.checkboxLimit) {
          this.selected = [...this.items.splice(0, this.checkboxLimit)];
          this.checkedItems = [...this.selected];
          this.lastSelection = [...this.selected];
          
          this.numberOfSelectedCheckboxes.emit(this.checkedItems.length);
          return
        }
        this.selected = [...selected];
        this.lastSelection = [...selected];
        this.checkedItems = [...selected];
        this.numberOfSelectedCheckboxes.emit(this.checkedItems.length);
    }    
  }

好吧,如果我按下 select 全部,它将 select 我需要的所有元素,而且我正在使用一个变量来了解之前的复选框 select编辑

好吧,我的问题是在执行此行之后:this.selected = [...this.lastSelection]; 变量 this.selected 被分配给了正确数量的元素。但是我浏览器中的 table 仍然选中了复选框。 但是,如果我向上或向下滚动直到复选框不可见,然后我尝试返回到它,则复选框未选中。

出于某种原因,它正在等待渲染。 有人对此有解决方案吗? 另外,我正在尝试执行 this.tableOffset = 0; (但不起作用)以尝试将 table 发送到顶部,只尝试再次渲染它,但我真的不需要那块代码。

我没有找到好的解决方案,我唯一的选择是使用警报控件,一旦用户在我的警报中按下确定,我就会触发该方法:

this.checkedItems = [...this.lastSelection];
this.selected = [...this.lastSelection];

我知道,这没有任何意义,但它奏效了。 我认为发生这种情况是因为它延迟了变量的更新。