【发布时间】:2019-11-29 09:15:39
【问题描述】:
'Picture a' 是我从 AJAX 调用中获得的数据。当一个任务的“dependencyTaskId”等于另一个任务的 ID 时,它成为该任务的子任务。如果“dependencyTaskId”为空,则该任务将处于顶层。最终结果将显示所有任务的树结构(“图片 b”)。
我正在使用 Angular 6。我怎样才能做到这一点?请帮我。非常感谢。
"orderId": 879530,
"status": "Processing",
"dateCreated": "2019-11-30T20:47:23.953",
"dateCommitted": "2019-11-30T20:47:25.627",
"dateModified": "2019-11-30T20:47:25.377",
"coreProducts": [
{
"coreProductId": 1597739,
"serviceAddress": {
"addressId": 7506180,
"locationId": "3472036",
"floor": null,
"buildingName": null,
"flatNumber": null,
"streetNumber": "30",
"streetNumberSubDescription": null,
"streetName": "LOGIE",
"streetDirection": null,
"suburb": "STOKES VALLEY",
"city": "LOWER HUTT",
"postCode": "5019",
"freeTextAddressOverride": null,
"attentionTo": null,
"careOf": null,
"addressType": "Service",
"addressAccessInformation": null
},
"coreProductKey": "NGA1000/500",
"contractLength": 12,
"requestedDateOfProvisioning": "2019-12-07T00:00:00",
"installationInstructions": null,
"coreProductComponents": [
{
"coreProductComponentId": 2245296,
"serviceIdentifier": "KoR157510004402",
"service": "Internet",
"ratePlan": "OR_access_NGA1000/500_U_Sep2019",
"overrideCharge": 0,
"electricityPriceOverrides": null
}
],
"coreProductCharges": null
}
],
"additionalProducts": [],
"hardwareOrders": [
{
"hardwareOrderId": 1829471,
"deliveryAddress": {
"addressId": 7506179,
"locationId": "3472036",
"floor": null,
"buildingName": null,
"flatNumber": null,
"streetNumber": "30",
"streetNumberSubDescription": null,
"streetName": "LOGIE",
"streetDirection": null,
"suburb": "STOKES VALLEY",
"city": "LOWER HUTT",
"postCode": "5019",
"freeTextAddressOverride": null,
"attentionTo": null,
"careOf": null,
"addressType": "Courier",
"addressAccessInformation": null
},
"linkedServiceIdentifier": "KoR157510004402",
"contract": null,
"hardwareOrderItems": [
{
"hardwareOrderItemId": 1828173,
"key": "NetCommNF18ACV_FIBRE_OR",
"type": null
}
]
}
],
"account": {
"accountId": 1939814,
"customers": [
{
"customerId": 1935666,
"firstName": "CC1FE844",
"lastName": "D007C",
"middleName": "",
"email": "76FC65F@gmail.com",
"homePhoneNumber": null,
"mobilePhoneNumber": "0212727822",
"workPhoneNumber": null,
"faxNumber": null,
"dateOfBirth": "1956-03-05T00:00:00",
"address": {
"addressId": 7506178,
"locationId": "3472036",
"floor": null,
"buildingName": null,
"flatNumber": null,
"streetNumber": "30",
"streetNumberSubDescription": null,
"streetName": "LOGIE",
"streetDirection": null,
"suburb": "STOKES VALLEY",
"city": "LOWER HUTT",
"postCode": "5019",
"freeTextAddressOverride": null,
"attentionTo": null,
"careOf": null,
"addressType": "PostalPhysical",
"addressAccessInformation": null
}
}
],
"organisationType": null,
"organisationReference": null,
"address": {
"addressId": 7506177,
"locationId": "3472036",
"floor": null,
"buildingName": null,
"flatNumber": null,
"streetNumber": "30",
"streetNumberSubDescription": null,
"streetName": "LOGIE",
"streetDirection": null,
"suburb": "STOKES VALLEY",
"city": "LOWER HUTT",
"postCode": "5019",
"freeTextAddressOverride": null,
"attentionTo": null,
"careOf": null,
"addressType": "PostalPhysical",
"addressAccessInformation": null
}
},
"losingServiceProviders": [
{
"losingServiceProviderId": 677663,
"serviceIdentifier": "KoR157510004402",
"serviceProvider": "ihug",
"accountName": "CEDC5BFE-53EE-4319",
"accountNumber": "20387451"
}
],
"questions": [
{
"questionAnswerId": 6329580,
"question": "LiveThereOrMovingIn",
"answer": "LiveThere",
"serviceIdentifier": "KoR157510004402"
},
{
"questionAnswerId": 6329581,
"question": "WhatServicesCurrentlyHave",
"answer": "BroadbandOnly",
"serviceIdentifier": "KoR157510004402"
}
],
"promoCodes": [
{
"promoCodeId": 2168141,
"promoCode": "GIGANTIC_PROMO",
"serviceIdentifier": "KoR157510004402"
}
],
"tasks": [
{
"taskId": 7670266,
"name": "ChorusGatewayNGAConnectPrimary",
"description": "Creates Chorus Gateway NGA NewConnection ticket",
"displayName": "Chorus Gateway NGA Connect Primary",
"dateStarted": "2019-11-30T20:47:34.617",
"dateCompleted": null,
"dateScheduled": null,
"taskSource": "CoreProducts",
"taskSourceId": "1597739",
"dependencyTaskId": null,
"ticketId": 36503526,
"ticketStatus": "With Provider",
"ticketPercentageComplete": 40,
"externalReferenceId": null,
"hasFailure": false,
"failureReason": "Complete"
},
{
"taskId": 7670268,
"name": "InternetActivation",
"description": "*InternetActivation",
"displayName": "Internet Activation",
"dateStarted": null,
"dateCompleted": null,
"dateScheduled": null,
"taskSource": "CoreProducts",
"taskSourceId": "1597739",
"dependencyTaskId": 7670266,
"ticketId": null,
"ticketStatus": null,
"ticketPercentageComplete": null,
"externalReferenceId": null,
"hasFailure": null,
"failureReason": null
},
{
"taskId": 7670271,
"name": "InternetUsageEvaluation",
"description": "Evaluates if the customer has internet usage",
"displayName": "Internet Usage Evaluation",
"dateStarted": null,
"dateCompleted": null,
"dateScheduled": null,
"taskSource": "CoreProducts",
"taskSourceId": "1597739",
"dependencyTaskId": 7670268,
"ticketId": null,
"ticketStatus": null,
"ticketPercentageComplete": null,
"externalReferenceId": null,
"hasFailure": null,
"failureReason": null
},
{
"taskId": 7670272,
"name": "CustomerCoreProductInsert",
"description": "Store LineNumber/Service data of a CoreProduct to customer tables.",
"displayName": "Customer Core Product Insert",
"dateStarted": null,
"dateCompleted": null,
"dateScheduled": null,
"taskSource": "CoreProducts",
"taskSourceId": "1597739",
"dependencyTaskId": 7670268,
"ticketId": null,
"ticketStatus": null,
"ticketPercentageComplete": null,
"externalReferenceId": null,
"hasFailure": null,
"failureReason": null
},
{
"taskId": 7670273,
"name": "NoUsageComms",
"description": "*NoUsageComms",
"displayName": "No Usage Comms",
"dateStarted": null,
"dateCompleted": null,
"dateScheduled": null,
"taskSource": "CoreProducts",
"taskSourceId": "1597739",
"dependencyTaskId": 7670266,
"ticketId": null,
"ticketStatus": null,
"ticketPercentageComplete": null,
"externalReferenceId": null,
"hasFailure": null,
"failureReason": null
},
{
"taskId": 7670269,
"name": "Hardware",
"description": "*Hardware",
"displayName": "Order Hardware",
"dateStarted": "2019-11-30T20:51:41.22",
"dateCompleted": null,
"dateScheduled": null,
"taskSource": "HardwareOrders",
"taskSourceId": "1828173",
"dependencyTaskId": 7670266,
"ticketId": 36503527,
"ticketStatus": "Scheduled",
"ticketPercentageComplete": 10,
"externalReferenceId": null,
"hasFailure": false,
"failureReason": "Complete"
},
{
"taskId": 7670270,
"name": "PromoCode",
"description": "Promo code task",
"displayName": "Promo Code Task",
"dateStarted": null,
"dateCompleted": null,
"dateScheduled": null,
"taskSource": "PromoCodes",
"taskSourceId": "2168141",
"dependencyTaskId": 7670268,
"ticketId": null,
"ticketStatus": null,
"ticketPercentageComplete": null,
"externalReferenceId": null,
"hasFailure": null,
"failureReason": null
},
{
"taskId": 7670267,
"name": "SaveQuestionsAndAnswers",
"description": "Save Questions And Answers",
"displayName": "Save Questions And Answers",
"dateStarted": "2019-11-30T20:47:33.307",
"dateCompleted": "2019-11-30T20:47:33.307",
"dateScheduled": null,
"taskSource": "SaveQuestionsAndAnswers",
"taskSourceId": "6329580",
"dependencyTaskId": null,
"ticketId": null,
"ticketStatus": null,
"ticketPercentageComplete": null,
"externalReferenceId": null,
"hasFailure": false,
"failureReason": "Complete"
}
],
"fulfilmentItems": []
}
【问题讨论】:
-
您可以控制这个 API 吗?如果是,那么我建议你在服务器上准备 JSON 数据作为父子数据,所以在前端你不需要做所有的事情
-
你需要一个递归函数
-
我愿意。据我了解,这种操作最好发生在前端。如我错了请纠正我。干杯
-
可以分享一下json数据吗?
-
@hbamithkumara。 Json 被添加到问题中。谢谢
标签: javascript angular iteration hierarchy