Skip to content

fetchTree just return 1 level child #13

@mhf-ir

Description

@mhf-ir

I use fake data to generate about 10 root menu and about 100 menu.

I have simple test unit with fake data:

          const tree = await Menu.fetchTree(0, rootId, {
            raw: true,
          });

Sample output:

[ { id: 10,
          lft: 1,
          rgt: 20,
          level: 0,
          rootId: 10,
          title: 'Root Menu 9',
          description:
           'Hic in molestiae sed vel sit quia. Totam nulla adipisci porro. Ipsam quo eligendi aut voluptatum nihil. Nesciunt voluptates doloribus pariatur dolor repudiandae.',
          url: '/page/9',
          enable: 1,
          createdAt: 2019-10-05T09:49:57.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z },
        { id: 16,
          lft: 2,
          rgt: 19,
          level: 1,
          rootId: 10,
          title: 'Child menu 4 : parent 10',
          description: 'et voluptas distinctio',
          url: '/child/page/4',
          enable: 1,
          createdAt: 2019-10-05T09:49:57.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z },
        { id: 85,
          lft: 3,
          rgt: 8,
          level: 2,
          rootId: 10,
          title: 'Child menu 73 : parent 16',
          description: 'Voluptatem veniam enim culpa maiores velit ut.',
          url: '/child/page/73',
          enable: 1,
          createdAt: 2019-10-05T09:49:58.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z },
        { id: 104,
          lft: 4,
          rgt: 7,
          level: 3,
          rootId: 10,
          title: 'Child menu 92 : parent 21',
          description: null,
          url: 'https://shaniya.net',
          enable: 1,
          createdAt: 2019-10-05T09:49:58.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z },
        { id: 110,
          lft: 5,
          rgt: 6,
          level: 4,
          rootId: 10,
          title: 'Child menu 98 : parent 104',
          description: 'Aut itaque unde commodi nostrum quos temporibus rerum.',
          url: '/child/page/98',
          enable: 1,
          createdAt: 2019-10-05T09:49:58.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z },
        { id: 23,
          lft: 9,
          rgt: 16,
          level: 2,
          rootId: 10,
          title: 'Child menu 11 : parent 16',
          description: null,
          url: '/child/page/11',
          enable: 1,
          createdAt: 2019-10-05T09:49:57.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z },
        { id: 34,
          lft: 10,
          rgt: 13,
          level: 3,
          rootId: 10,
          title: 'Child menu 22 : parent 21',
          description: null,
          url: 'http://britney.net',
          enable: 1,
          createdAt: 2019-10-05T09:49:57.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z },
        { id: 70,
          lft: 11,
          rgt: 12,
          level: 4,
          rootId: 10,
          title: 'Child menu 58 : parent 27',
          description: null,
          url: '/child/page/58',
          enable: 0,
          createdAt: 2019-10-05T09:49:58.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z },
        { id: 27,
          lft: 14,
          rgt: 15,
          level: 3,
          rootId: 10,
          title: 'Child menu 15 : parent 23',
          description: 'velit',
          url: '/child/page/15',
          enable: 1,
          createdAt: 2019-10-05T09:49:57.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z },
        { id: 21,
          lft: 17,
          rgt: 18,
          level: 2,
          rootId: 10,
          title: 'Child menu 9 : parent 16',
          description: null,
          url: 'https://hester.name',
          enable: 0,
          createdAt: 2019-10-05T09:49:57.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z } ]

Desire output:

[ { id: 10,
          lft: 1,
          rgt: 20,
          level: 0,
          rootId: 10,
          title: 'Root Menu 9',
          description:
           'Hic in molestiae sed vel sit quia. Totam nulla adipisci porro. Ipsam quo eligendi aut voluptatum nihil. Nesciunt voluptates doloribus pariatur dolor repudiandae.',
          url: '/page/9',
          enable: 1,
          createdAt: 2019-10-05T09:49:57.000Z,
          updatedAt: 2019-10-05T09:49:58.000Z
         // here
        children: [
           // same as above
        ],
 } ]

My full table json dump: https://paste.ubuntu.com/p/67sy2dhJkr/

Where is children of children of children.

i'v try depth 10 or any number but array return me one step of child.

Use case VueJS Menu: https://jsfiddle.net/chrisvfritz/pnqzspoe

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions