在Angular中基于复杂JSON在Angular中创建表单

时间:2019-09-10 09:40:22

标签: json angular angular-reactive-forms reactive-forms

我正在使用Angular Web应用程序。在一个组件中,我收到一个复杂的JSON,我需要创建一个尊重JSON结构的反应形式。只是为了展示我的JSON的示例:

{
    "annoAl": 2019,
    "annoDal": 2019,
    "azienda": {
        "id": 1,
        "uuid": null,
        "codice": "201",        
        "regioneId": 1,
        "sigla": "dummy"
    },
    "comune": null,
    "descrizione": "Turno ripartito",
    "giorni": [{
        "chiuso": false,
        "orari": [{
            "start": null,
            "end": null
        },
        {
            "start": null,
            "end": null
        }]
    },
    {
        "chiuso": false,
        "orari": [{
            "start": null,
            "end": null
        },
        {
            "start": null,
            "end": null
        }]
    },
    {
        "chiuso": false,
        "orari": [{
            "start": null,
            "end": null
        },
        {
            "start": null,
            "end": null
        }]
    }],
    "invertiIntervallo": false,
    "meseGiornoAl": null,
    "meseGiornoDal": null,
    "provenienza": "AZIENDA",
    "regione": null,
    "ripartizione": {
        "durataTurno": 7,
        "gruppi": [{
            "gruppo": 0,
            "sede": {
                "id": 11,
                "uuid": "11",
                "idFarmacia": 13,
                "idComune": 163,                
            }
        },
        {
            "gruppo": 1,
            "sede": {
                "id": 12,
                "uuid": "12",
                "idFarmacia": 11,
                "idComune": 163,                
            }
        },
        {
            "gruppo": 2,
            "sede": {
                "id": 8,
                "uuid": "8",
                "idFarmacia": 8,
                "idComune": 164,                
            }
        }],
        "gruppiNumero": 4
    },
    "ripetiAnnualmente": false,
    "sede": null,
    "tipo": "TURNO_RIPARTITO",
    "uuid": null
}

为完成此任务,我手动构建了反应形式(这些字段是已知的)。有没有简单的方法可以做到这一点?我尝试使用FormBuilder,但是数组存在一些问题。

formBuilder.group(jsonObject)

谢谢

0 个答案:

没有答案