角反应形式从服务中嵌套数据加载

时间:2018-06-21 15:39:50

标签: angular5

这是我从服务中获得的结果

{
    "id": 1,
    "name": "Asp.Net Quiz",
    "description": "Asp.Net Quiz (contains webform, mvc, web API, etc.)",
    "questions": [
        {
            "id": 1010,
            "name": "ASP.NET webform separates the HTML output from program logic using a feature named as",
            "questionTypeId": 1,
            "options": [
                {
                    "id": 1055,
                    "questionId": 1010,
                    "name": "Exception",
                    "isAnswer": false
                },
                {
                    "id": 1056,
                    "questionId": 1010,
                    "name": "Code-behind",
                    "isAnswer": true
                },
                {
                    "id": 1057,
                    "questionId": 1010,
                    "name": "Code-front",
                    "isAnswer": false
                },
                {
                    "id": 1058,
                    "questionId": 1010,
                    "name": "None of the above",
                    "isAnswer": false
                }
            ],
            "questionType": {
                "id": 1,
                "name": "Multiple Choice",
                "isActive": true
            }
        },
        {
            "id": 1011,
            "name": "The feature in ASP.NET 2.0 that is used to fire a normal postback to a different page in the application is called",
            "questionTypeId": 1,
            "options": [
                {
                    "id": 1055,
                    "questionId": 1010,
                    "name": "Theme",
                    "isAnswer": false
                },
                {
                    "id": 1057,
                    "questionId": 1010,
                    "name": "Code-front",
                    "isAnswer": false
                },
                {
                    "id": 1056,
                    "questionId": 1010,
                    "name": "Cross Page Posting",
                    "isAnswer": true
                },
                {
                    "id": 1058,
                    "questionId": 1010,
                    "name": "None of the above",
                    "isAnswer": false
                }
            ],
            "questionType": {
                "id": 1,
                "name": "Multiple Choice",
                "isActive": true
            }
        }       
    ]
}

这是我为响应式表格加载的代码

ngOnInit () {  
    this.questionerForm = this.fb.group({ 
        id:'',
        name: '',
        description: '',        
        questions: this.fb.array([
            this.fb.group({
                id:'',
                name: '',
                questionTypeId: '',        
                options: this.fb.array([
                    this.fb.group({  id:'',
                    questionId:'',
                    isAnswer:'',
                    selected:''                    
                })
                ])

            })         
        ])
    });              
}

但是我在问题数组中只得到一个记录集。 我的提问者表格中有什么问题,如何完美构建。

0 个答案:

没有答案