array-to-tree
array-to-tree copied to clipboard
Options parentPropety not working as expected
hi guys, he's the issue I'm facing using parentProperty options.
var data2 =[ { id: 1, created_at: '2020-05-09T16:13:04.896Z', folder_id: 1, 'Filess.name': 'MyFirstLesson' }, { id: 2, created_at: '2020-05-11T16:13:04.896Z', folder_id: 2, 'Filess.name': 'MyFirstLesson' }, { id: 3, created_at: '2020-05-11T16:13:04.896Z', folder_id: 3, 'Filess.name': 'MyFirstLesson' }, { id: 4, created_at: '2020-05-09T16:13:04.896Z', folder_id: 1, 'Filess.name': 'Meeting1' }, { id: 5, created_at: '2020-05-16T16:13:04.896Z', folder_id: 1, 'Filess.name': 'SetupRoom' }, { id: 6, created_at: '2020-05-17T16:13:04.896Z', folder_id: 1, 'Filess.name': 'SetupRoom' }, { id: 7, created_at: '2020-05-17T16:13:04.896Z', folder_id: 1, 'Filess.name': 'SetupRoom' }, { id: 8, created_at: '2020-05-20T15:26:36.656Z', folder_id: 1, 'Filess.name': 'Annotation 2020-04-08 135240.jpg' } ]
arrayToTree(data2, {parentProperty: 'folder_id})
returns empty array
I think this is because your top-level node is pointing to itself i.e. it has id and folder_id both equal to 1
{
id: 1,
created_at: '2020-05-09T16:13:04.896Z',
folder_id: 1,
'Filess.name': 'MyFirstLesson'
},