Lodash中的多个分组

我有这个样本数据要分组

 [
            {
                heading: "pikachu",
                sideHeading: "yellow",
                subSideHeading: "electric",
                comment: "its a pokemon"
            },
            {
                heading: "pikachu",
                sideHeading: "yellow",
                subSideHeading: "rat",
                comment: "Ash pokemon"
            },
            {
                heading: "bulbasaur",
                sideHeading: "green",
                subSideHeading: "frog",
                comment: "Ash pokemon"
            },
            {
                heading: "pikachu",
                sideHeading: "ash",
                subSideHeading: "pet",
                comment: "not in pokeball"
            }
 ]

寻找lodash方法可以让我得到这个输出:

  [
        {
            heading:"pikachu",
            sideHeading:
            [
                {
                    sideHeading:"yellow",
                    subSideHeading:
                    [
                        {
                            subSideHeading: "electric",
                            comment: "its a pokemon"
                        },
                        {
                            subSideHeading: "rat",
                            comment: "Ash pokemon"
                        }
                    ]
                },
                {
                    sideHeading:"ash",
                    subSideHeading:[
                        {
                            subSideHeading: "pet",
                            comment: "not in pokeball"
                        }
                    ]
                }
            ]
        },
        {
            heading:"bulbasaur",
            sideHeading:
            [
                {
                    sideHeading:"green",
                    subSideHeading:
                    [
                        {
                            subSideHeading: "frog",
                            comment: "Ash pokemon"
                        }
                    ]
                }
            ]
        }
    ]

I tried very hard referring lodash documentation and stack overflow questions and used the methods like chain groupBy each map filter but the luck was not in my favor. Can anyone come up with the solution to solve this or direct me to the correct path.

评论