简体   繁体   中英

Get selected checkbox values from parent and child in angular

I am trying to generate a new array from this data and show only selected checkbox values from parent as well child.

this.data.ParentChildchecklist = [ { id: 1,value: 'Elenor Anderson',isSelected: false,isClosed:false, childList: [ { id: 1,parent_id: 1,value: 'child 1',isSelected: false }, { id: 2,parent_id: 1,value: 'child 2',isSelected: false } ] }, { id: 2,value: 'Caden Kunze',isSelected: false,isClosed:false,childList: [ { id: 1,parent_id: 1,value: 'child 1',isSelected: false }, { id: 2,parent_id: 1,value: 'child 2',isSelected: false } ] }, { id: 3,value: 'Ms. Hortense Zulauf',isSelected: false,isClosed:false, childList: [ { id: 1,parent_id: 1,value: 'child 1',isSelected: false }, { id: 2,parent_id: 1,value: 'child 2',isSelected: false } ] } ];

Tried this code to filter the selected list from parent and child to push to new List but its not working.

https://stackblitz.com/edit/angular-ivy-hfvrqa?file=src/app/app.component.ts

there is an error in your example

this line maybe should be removed

this.checkedList.ParentChildchecklist.push(
    obj.ParentChildchecklist[i].childList[j]
);

because this.checkedList.ParentChildchecklist does not exist

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