array-to-tree icon indicating copy to clipboard operation
array-to-tree copied to clipboard

Options parentPropety not working as expected

Open immersivevreducation opened this issue 5 years ago • 1 comments

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

immersivevreducation avatar May 21 '20 09:05 immersivevreducation

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'
},

rcoundon avatar Nov 02 '20 12:11 rcoundon