如何从角度的多个复选框列表中获取多个选定的复选框项目 [英] How to get multiple selected checkbox item from multiple checkbox list in angular

查看:50
本文介绍了如何从角度的多个复选框列表中获取多个选定的复选框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里复制最少https://stackblitz.com/edit/angular-uwfsyv?file=app%2Fapp.component.html,我有 2 个数组,checkboxesDataListcheckboxesDataList2 我成功地得到了检查来自 checkboxesDataList 的标签,但这只是一个例子.

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.

但是我想在我的项目中得到类似于 checkboxesDataList2 在这里我有对象 questioncheckboxesDataList 没有那个所以这个功能

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;
    });
  }

如果我将 this.checkboxesDataList 更改为 this.checkboxesDataList2 将不会立即工作,我该如何使其工作?

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])
}

这篇关于如何从角度的多个复选框列表中获取多个选定的复选框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆