如何从角度的多个复选框列表中获取多个选中的复选框项目 [英] How to get multiple selected checkbox item from multiple checkbox list in angular
问题描述
我在这里的复制量很少 https://stackblitz.com/edit/angular-uwfsyv?file = app%2Fapp.component.html ,我有2个数组,分别是 checkboxesDataList
和 checkboxesDataList2
来自 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
,在这里我有对象 question
和 checkboxesDataList
没有所以这个功能
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屋!