【发布时间】:2020-04-03 09:16:42
【问题描述】:
我们有一个嵌套 JSON 对象,用于对象导出 CSV 的平面级别的 json 正在工作,但对于嵌套对象它不起作用 (站点对象)。
对于这个实现,我们使用了 PrimeNg 库:
以下是 json 响应:
"data": [
{
"towerId": "gfsjfdy32ur",
"towerName": "qjdhkud",
"exAxisTower": false,
"tbuShareable": null,
"technologyPartnerRNP": "TP_RNP_EID",
"technologyPartnerTNP": "TP_TNP_EID",
"ssrLongitude": "323",
"ssrLatitude": "323",
"region": "REG_J",
"province": "PROV_SU",
"district": "PROV_SU_D1",
"scheme": null,
"towerType": "TYPE_CL",
"towerKind": null,
"category": "CAT_SM",
"proposedHeight": 323,
"useShelter": "SHELT_Y",
"azimuth": "dewdew",
"towerProviderNumber": null,
"towerProviderName": null,
"farEnd1": null,
"farEnd2": null,
"farEnd3": null,
"towerStatus": "Plan on Progress",
"projectStatus": "SSR Completed",
"sites": [
{
"id": "6a056c60-5774-40ad-bd00-2523cbfdb8a4",
"created": "2019-12-09T10:52:18.293+0000",
"createdId": "ff06c5a4-135c-40b7-83f3-3648ec035efc",
"modified": "2019-12-09T10:52:18.293+0000",
"modifiedId": "ff06c5a4-135c-40b7-83f3-3648ec035efc",
"siteId": "siteid value 1",
"siteName": "site name value 1",
"ssrId": "d6c4fa53-a8f3-4b53-b592-a0c1646c1d46"
},
{
"id": "6a056c60-5774-40ad-535434",
"created": "2019-12-09T10:52:18.293+0000",
"createdId": "ff06c5a4-135c-40b7-83f3-3648ec035efc",
"modified": "2019-12-09T10:52:18.293+0000",
"modifiedId": "ff06c5a4-135c-40b7-83f3-3648ec035efc",
"siteId": "site Id value 1",
"siteName": " site Name value2",
"ssrId": "d6c4fa53-a8f3-4b53-b592-a0c1646c1d46"
}
],
"projectName": "fje",
"commitmentNumber": null,
"rfiSLA": null,
"trialPeriod": null,
"cmeType": null,
"ownerShip": null,
"banDocument": null,
"slaDocument": null
},
{
"towerId": "327",
"towerName": "dws",
"exAxisTower": false,
"tbuShareable": null,
"technologyPartnerRNP": "TP_RNP_EID",
"technologyPartnerTNP": "TP_TNP_EID",
"ssrLongitude": "324234",
"ssrLatitude": "34324",
"region": "REG_J",
"province": "PROV_AC",
"district": "PROV_AC_D2",
"scheme": null,
"towerType": "TYPE_CL",
"towerKind": null,
"category": "CAT_MA",
"proposedHeight": 434,
"useShelter": "SHELT_Y",
"azimuth": "2342432",
"towerProviderNumber": null,
"towerProviderName": null,
"farEnd1": null,
"farEnd2": null,
"farEnd3": null,
"towerStatus": "Plan on Progress",
"projectStatus": "SSR Completed",
"sites": [
{
"id": "00db69ed-dfd0-439a-a879-bc8dfaf5a9bf",
"created": "2019-12-09T10:54:06.686+0000",
"createdId": "ff06c5a4-135c-40b7-83f3-3648ec035efc",
"modified": "2019-12-09T10:54:06.686+0000",
"modifiedId": "ff06c5a4-135c-40b7-83f3-3648ec035efc",
"siteId": "",
"siteName": "",
"ssrId": "761e6545-9179-4fbb-8c80-eaa0c8095ad7"
}
],
"projectName": "ewe",
"commitmentNumber": null,
"rfiSLA": null,
"trialPeriod": null,
"cmeType": null,
"ownerShip": null,
"banDocument": null,
"slaDocument": null
}
]
CSV 必须像以下格式一样导出:
假设 sites 对象 中有 nth 对象,那么这些 许多网站 ID 和网站名称 需要在 csv 导出时添加。 p>
我们正在使用 primeNg 表。
【问题讨论】:
-
对于导出 csv 文件,我之前有一个解决方案,请参阅:stackoverflow.com/questions/58926366/…
-
您可以使用相同的并根据需要在导出前编辑数据
-
@JoelJoseph,我们可以对 PrimeNg 表导出 CSV 做同样的事情吗?
-
你基本上是在将
json的数据转成table,你可以用一样,请看文章 -
你可以使用上面的 json 数据在 stackblitz 上创建一个演示吗?
标签: angular angular7 export-to-csv primeng-table