简体   繁体   中英

How to get multiple selected checkbox item from multiple checkbox list in angular

i have minimal reproduce here https://stackblitz.com/edit/angular-uwfsyv?file=app%2Fapp.component.html , there i have 2 array, checkboxesDataList and checkboxesDataList2 i successfully get the checked label from checkboxesDataList but that's just for an example.

but what i wanted to get in my project is similar to checkboxesDataList2 inside here i have object question and checkboxesDataList don't have that so this function

  fetchSelectedItems() {
    this.selectedItemsList = this.checkboxesDataList.filter((value, index) => {
      return value.checked;
    });
  }

won't work immediately if i change this.checkboxesDataList to this.checkboxesDataList2 how can i make it work?

do you want to has a function like?

getDataChecked()
{
    return this.checkboxesDataList2.question
          .map(x=>x.options.filter(o=>o.checked))
          .reduce((acc, value)=>[...acc,...value])
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM