[英]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.我在这里有最少的复制https://stackblitz.com/edit/angular-uwfsyv?file=app%2Fapp.component.html ,我有 2 个数组,
checkboxesDataList
和checkboxesDataList2
我成功地从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但是我想在我的项目中得到的类似于这里的
checkboxesDataList2
我有对象question
而checkboxesDataList
没有,所以这个功能
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?如果我将
this.checkboxesDataList
更改为this.checkboxesDataList2
将不会立即工作我怎样才能让它工作?
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])
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.