首页 > 解决方案 > 将类添加到特定的 ng-multiselect-dropdown 项目

问题描述

我正在使用ng-multiselect-dropdown,我想为列表中的特定项目添加一个

HTML

<ng-multiselect-dropdown
[data]="mydata"
[settings]="mysettings"
>
</ng-multiselect-dropdown>

打字稿

有没有办法做这样的事情?

tempList[i] = { ...tempList[i], **cssClass: 'my css code'** };}
getData() {
    this.service.getData().subscribe((resp: any) => {
      const tempList = resp;
      for (let i = 0; i < tempList.length; i++) {
        if(mycondition()){
            tempList[i] = { ...tempList[i], cssClass: 'my css code' };
        }
      }
      this.mydata = tempList;
    }, () => {

    });
}

标签: htmlangular

解决方案


multiselect-item-checkbox在 style.css 中添加 CSS

.multiselect-item-checkbox{
  background: cornflowerblue!important;
}

当您使用条件进行过滤时,这意味着所有对象都mydata应该使用一种 CSS 样式。所以我们可以添加样式一次。

在此处输入图像描述


推荐阅读