gpt4 book ai didi

javascript - 扁平化 JSON 数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:38:08 26 4
gpt4 key购买 nike

我正在尝试使用 Tabulator 创建工单列表,数据通过 AJAX url 从工单系统导入为 JSON,如下所示。

{
"results": [
{
"cc_emails": [
"ram@freshdesk.com",
"diana@freshdesk.com"
],
"fwd_emails": [],
"reply_cc_emails": [
"ram@freshdesk.com",
"diana@freshdesk.com"
],
"ticket_cc_emails": [
"ram@freshdesk.com",
"diana@freshdesk.com"
],
"fr_escalated": false,
"spam": false,
"email_config_id": null,
"group_id": 35000204315,
"priority": 1,
"requester_id": 35020281588,
"responder_id": 35004154466,
"source": 2,
"company_id": null,
"status": 2,
"subject": "Support Needed...",
"association_type": null,
"to_emails": null,
"product_id": null,
"id": 188261,
"type": null,
"due_by": "2019-09-17T15:12:07Z",
"fr_due_by": "2019-07-01T15:12:07Z",
"is_escalated": false,
"description": "<div>Details about the issue...</div>",
"description_text": "Details about the issue...",
"custom_fields": {
"cf_category": null,
"cf_firstname": null,
"cf_surname": null,
"cf_user_trainging": null,
"cf_email_address": null,
"cf_office_365": null,
"cf_start_date": null,
"cf_permission_level": null,
"cf_hardware_type": null,
"cf_additional_information_specsoftware_etc": null,
"cf_vpn_access_required": false,
"cf_securitydistribution_group_membership": null,
"cf_mapped_network_driveslogin_script": null,
"cf_printers": null,
"cf_phone_extension": null,
"cf_ddi": null,
"cf_phone_group_membership": null,
"cf_user_who_requires_the_equipment": null,
"cf_requirment_date": null,
"cf_correctclosureused": null,
"cf_location": "A1"
},
"created_at": "2019-06-24T15:11:47Z",
"updated_at": "2019-06-24T15:59:00Z",
"associated_tickets_count": null,
"tags": []
}
],
"total": 1
}

问题是“custom_fields”是主 JSON 对象内的一个 JSON 对象,有没有办法将这些数据展平并在 Tabulator 中显示为所有一行?有什么帮助吗?

我在 Tabulator 中的当前结果是它为 custom_fields 列返回 [object Object]。我希望能够看到行中的每个 custom_fields。

最佳答案

处理嵌套数据

不需要扁平化对象,Tabulator可以处理列的嵌套数据,如果你在字段名中使用点符号:

var table = new Tabulator("#example-table", {
columns:[
{title:"Category", field:"custom_fields.cf_category"}, //link column to nested field
],
});

有关嵌套数据处理的完整详细信息可以在 Columns Documentation 中找到

列分组

如果您愿意,您还可以使用列分组来显示字段是另一个属性的子集,例如,我们可以像往常一样定义顶级列,然后添加列组来保存自定义列

var table = new Tabulator("#example-table", {
columns:[
{title:"Subject", field:"subject"}, //standard column
{title:"Priorty", field:"priority"}, //standard column
{title:"Custom", columns:[ //column group to hold columns in custom_fields property
{title:"Category", field:"custom_fields.cf_category"},
{title:"First Name", field:"custom_fields.cf_firstname"},
]},
],
});

完整的详细信息可以在 Column Grouping Documentation 中找到

关于javascript - 扁平化 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56753708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com