如何以角5反应形式迭代formarray内部的formarray

时间:2019-04-09 16:43:11

标签: angularjs angular5 angular-reactive-forms angular4-forms

我想在angualar5项目反应形式中的formArry中迭代formArray, 我尝试保留两个fromArray,parent(initSection)和child(ini​​tQuestion),请参考以下工作网址: https://stackblitz.com/edit/deep-nested-reactive-form-1p9mza?file=app/app.component.ts

在每个用户3个问题的子数组中,有人可以建议如何迭代我的父数组或两个用户项吗?以及如何在提交时映射与问题对应的所选单选按钮值?

UI设计如下所示

enter image description here

下面是我的输入

 this.userList =  [
            {
                "name": "sam",
                "questionsList":[
                    {
                        "question": "question 0111111?"
                    },
                    {
                        "question": "question 0222222?"
                    },
                    {
                        "question": "question 03333333?"
                    }
                ]
            },
            {
                "name": "robert",
                "questionsList":[
                    {
                        "question": "question 0111111?"
                    },
                    {
                        "question": "question 0222222?"
                    },
                    {
                        "question": "question 03333333?"
                    }
                ]
            }
        ]

当用户提交我的表单时,我希望输出如下所示:

userList: [
            {
                "name": "sam",
                "questionsList":[
                    {
                        "question": "question 0111111?",
                        "isSelected": "yes"
                    }
                    {
                        "question": "question 0222222?",
                        "isSelected": "no"
                    }
                    {
                        "question": "question 03333333?",
                        "isSelected": "yes"
                    }
                ]
            },
            {
                "name": "robert",
                "questionsList":[
                    {
                        "question": "question 0111111?",
                        "isSelected": "no"
                    }
                    {
                        "question": "question 0222222?",
                        "isSelected": "yes"
                    }
                    {
                        "question": "question 03333333?",
                        "isSelected": "no"
                    }
                ]
            }
        ]

0 个答案:

没有答案