-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Description
Seems like there is a wrong documentation for the convert util function, I tried to use it and it didn't work, e.g:
const items = [
{id: 1, parentId: null, index: 0, name: "Categories"},
{id: 2, parentId: null, index: 1, name: "Brand"},
{id: 3, parentId: 1, index: 0, name: "Bags"},
{id: 4, parentId: 1, index: 1, name: "Mugs"},
{id: 5, parentId: 1, index: 2, name: "Clothing"},
{id: 8, parentId: 2, index: 0, name: "Ruby"},
{id: 9, parentId: 2, index: 1, name: "Apache"},
{id: 10, parentId: 2, index: 2, name: "Spree"},
{id: 11, parentId: 2, index: 3, name: "Rails"}
];
const convertedItems = convert(items);
The result for convertedItems is an empty array.
Solution
The thing is that the database data must not have null as a parentId for the first level items.
The data must look something like this:
const items = [
{id: 1, parentId: 0, index: 0, name: "Categories"},
{id: 2, parentId: 0, index: 1, name: "Brand"},
{id: 3, parentId: 1, index: 0, name: "Bags"},
{id: 4, parentId: 1, index: 1, name: "Mugs"},
{id: 5, parentId: 1, index: 2, name: "Clothing"},
{id: 8, parentId: 2, index: 0, name: "Ruby"},
{id: 9, parentId: 2, index: 1, name: "Apache"},
{id: 10, parentId: 2, index: 2, name: "Spree"},
{id: 11, parentId: 2, index: 3, name: "Rails"}
];
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels