简体   繁体   English

如何将数据从数组转换为angular13中的嵌套数组数据

[英]How to convert data from an array to a nested array data in angular13

i'm new to angular. I need to convert the data as nested array in angular13.我是 angular 的新手。我需要将数据转换为 angular13 中的嵌套数组。 A stackblitz example is appreciated stackblitz 示例表示赞赏

Data I got from the random API我随机得到的数据 API

"data": [
            {
                "Id": "17",
                "Year": "2020",
                "MonthName": "December",
                "Details": "Start the process ",
                "DisplayOrder": "3",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "16",
                "Year": "2020",
                "MonthName": "August",
                "Details": "Conduct an online ",
                "DisplayOrder": "2",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "15",
                "Year": "2020",
                "MonthName": "January",
                "Details": "Complete a minimum wage ",
                "DisplayOrder": "1",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "12",
                "Year": "2019",
                "MonthName": "September",
                "Details": "Start professions",
                "DisplayOrder": "3",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "11",
                "Year": "2019",
                "MonthName": "September",
                "Details": "Formulate Family Model",
                "DisplayOrder": "2",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "13",
                "Year": "2019",
                "MonthName": "October",
                "Details": "Complete technical research",
                "DisplayOrder": "1",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "14",
                "Year": "2019",
                "MonthName": "December",
                "Details": "Complete technical research service",
                "DisplayOrder": "1",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "10",
                "Year": "2019",
                "MonthName": "September",
                "Details": "Formulate Occupation",
                "DisplayOrder": "1",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "9",
                "Year": "2018",
                "MonthName": "October",
                "Details": "Approved officially",
                "DisplayOrder": "3",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "8",
                "Year": "2018",
                "MonthName": "October",
                "Details": "Start technical research",
                "DisplayOrder": "2",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "7",
                "Year": "2018",
                "MonthName": "October",
                "Details": "Publish a number completed",
                "DisplayOrder": "1",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "6",
                "Year": "2017",
                "MonthName": "October",
                "Details": "Formulate Commission",
                "DisplayOrder": "5",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "5",
                "Year": "2017",
                "MonthName": "May",
                "Details": "Complete the formulation",
                "DisplayOrder": "4",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "4",
                "Year": "2017",
                "MonthName": "April",
                "Details": " Initiate relevant Act.",
                "DisplayOrder": "3",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "3",
                "Year": "2017",
                "MonthName": "March",
                "Details": "Started the process employees",
                "DisplayOrder": "2",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "2",
                "Year": "2017",
                "MonthName": "February",
                "Details": "Started the process allowances",
                "DisplayOrder": "1",
                "LanguageID": "1",
                "Hide": null
            },
            {
                "Id": "1",
                "Year": "2016",
                "MonthName": "October",
                "Details": "Members appointed",
                "DisplayOrder": "1",
                "LanguageID": "1",
                "Hide": null
            }
        ],

But I need data like this.但我需要这样的数据。 Is it possible in angular 13? angular 13可以吗?

 "data": [
            {
                "Year": "2020",
                "Month": [
                    {
                        "Id": "17",
                        "MonthName": "December",
                        "Details": "Start the process",
                        "DisplayOrder": "3",
                        "LanguageID": "1",
                        "Hide": null
                    },
                    {
                        "Id": "16",
                        "MonthName": "August",
                        "Details": "Conduct an online",
                        "DisplayOrder": "2",
                        "LanguageID": "1",
                        "Hide": null
                    },
                    {
                        "Id": "15",
                        "MonthName": "January",
                        "Details": "Complete wage ",
                        "DisplayOrder": "1",
                        "LanguageID": "1",
                        "Hide": null
                     },
                ]
            },
            {
                "Year": "2019",
                "Month": [
                    {
                        "Id": "12",
                        "MonthName": "September",
                        "Details": "Start formulating",
                        "DisplayOrder": "3",
                        "LanguageID": "1",
                        "Hide": null
                    }
                ]
            },
            {
                "Year": "2018",
                "Month": [
                    {
                        "Id": "9",
                        "MonthName": "October",
                        "Details": "Approved officially",
                        "DisplayOrder": "3",
                        "LanguageID": "1",
                        "Hide": null
                    }
                ]
            },
            {
                "Year": "2017",
                "Month": [
                    {
                        "Id": "6",
                        "MonthName": "October",
                        "Details": "Formulate Commission",
                        "DisplayOrder": "5",
                        "LanguageID": "1",
                        "Hide": null
                    }
                ]
            },
            {
                "Year": "2016",
                "Month": [
                    {
                        "Id": "1",
                        "MonthName": "October",
                        "Details": "Members appointed",
                        "DisplayOrder": "1",
                        "LanguageID": "1",
                        "Hide": null
                    }
                ]
            }
        ],

The above data is the expected array to loop in html to get the desired result.上面的数据是预期的数组,在 html 中循环得到想要的结果。

This is a basic data ordering/parsing exercise, actually quite similar to a question I answered a few days ago .这是一个基本的数据排序/解析练习,实际上与我几天前回答的一个问题非常相似。

As you iterate over it, you can group and map/reduce in order to output your own new structure.当您对其进行迭代时,您可以分组和映射/缩减,以便 output 您自己的新结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何避免使用angular13将更新的值绑定到其他数组 - how to avoid the updated value to be binded to other array using angular13 如何将对象数组与 object 键值进行比较,如果匹配保留,如果不使用 angular13 过滤掉 - how to compare array of objects with object key value, if matches retain if not filter out using angular13 为什么数据在 angular13 中没有正确传递? - why data is not passing in route correctly in angular13? 使用 angular13 将 responsetype 用作 post 方法的 arrayBuffer 时如何获取错误数据 - how to get the error data when using responsetype as arrayBuffer for post method using angular13 如何显示嵌套 Web 服务数组中的数据(Angular 4) - How to show data from nested web service array (Angular 4) 如何将数据推送到 angular 上的嵌套数组? - How to push data to nested array on angular? 如何在 Angular 中过滤嵌套数组中的数据 - How to filter data in a nested array in Angular Angular / 如何将获取的数据从字符串转换为数组 - Angular / how can i convert fetched data from string to array 如何在angular2的表单数组中显示嵌套数组数据? - How can display nested array data in form array in angular2? 从 angular13 中的服务获取未定义的值 - Getting an UNDEFINED value from services in angular13
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM