【发布时间】:2020-10-08 05:49:27
【问题描述】:
我使用 Angular 设计了一个应用程序,该应用程序使用 ASP.NET 制作的后端链接到数据库 我的问题是我在前端的 JSON 与后端的 JSON 有点不同。 我需要有关如何映射前端 JSON 以将其发送到后端的帮助。
psd:我在前端创建了所有的接口,我在前端使用了formControls和FormArrays来存储数据,问题是de JSON有点不同。 我无法更改后端的 JSON,因为它与 DB 链接并且它具有 PK 和 FK,所以这就是原因,因为它有点不同。 我正在考虑做类似 this.myform.value 的事情并映射到另一个界面,但我不知道该怎么做,因为我有数组数组...... 也许是一个 for 循环?
这是我的前端 JSON:
{
"non-array fields....................." : "bla bla",
"arraySustancias": [
{
"sustanciaActiva": "hello",
"contenido": "2",
"suministro": ["hello2","hello3"],
"unidades": "3"
}
],
"arrayProcedimientos": [
{
"procedimiento": "",
"fechaInicioProcedimiento": "",
"fechaFinProcedimiento": "",
"notasProcedimiento": "",
"arraySubprocedimientos": [
{
"subprocedimiento": "",
"fechaInicioSubProcedimiento": "",
"fechaFinSubProcedimiento": "",
"notasSubProcedimiento": "",
"exp": ""
}
]
}
]
}
这是我的后端 JSON:
{
"non-array fields.....................": "bla bla",
"registros_arraySustancias": [
{
"registros_arraySustancias_suministro": [
{
"registros_arraySustancias_id": "",
"id": "",
"value": [
"ABBOTT LABORATORIES",
"ADAMA Agan Ltd."
]
}
],
"registros_id": "",
"id": "",
"sustanciaActiva": "hola",
"contenido": 2,
"unidades": 3
}
],
"registros_arrayProcedimientos": [
{
"registros_id": "",
"id": "",
"procedimiento": "text",
"fechaInicioProcedimiento": "18/06/2020",
"fechaFinProcedimiento": "18/06/2020",
"notasProcedimiento": "notes",
"registros_arrayProcedimientos_arraySubprocedimientos": [
{
"registros_arrayProcedimientos_id": "",
"id": "",
"subprocedimiento": "text",
"fechaInicioSubProcedimiento": "19/06/2020",
"fechaFinSubProcedimiento": "19/06/2020",
"notasSubProcedimiento": "notes"
}
]
}
]
}
感谢您的帮助:)
【问题讨论】:
-
id 或_id 字段都是主键和外键,是自增的,不需要有值。
-
我的意思是,这里的问题是什么?你从哪里得到那个 JSON?您可以更改生成的格式,或者您只需编写一个转换它的函数。在 TypeScript/JavaScript 中,您可以只将 JSON 作为对象,然后必须将其分配给不同结构的对象。你要我们做什么,一行一行的给你写好?
-
并不是所有的代码我都有关于如何做到这一点的理论,我只需要一个小例子或类似的例子来说明如何做到这一点。 @BenjaminMaurer