Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options parentPropety not working as expected #20

Open
immersivevreducation opened this issue May 21, 2020 · 1 comment
Open

Options parentPropety not working as expected #20

immersivevreducation opened this issue May 21, 2020 · 1 comment

Comments

@immersivevreducation
Copy link

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

@rcoundon
Copy link

rcoundon commented Nov 2, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants