-
Notifications
You must be signed in to change notification settings - Fork 39
Closed
Description
Here's my data structure:
const array = [
{ data: { id: 'id1', parent: 'idparent' , otherdata...} },
{ data: { id: 'id2', parent: 'id1' , otherdata...} },
{ data: { id: 'id3', parent: 'id1' , otherdata...} }
]
id and parentId are nested inside data in my case, and I'd bet it is not uncommon.
Would you amend your code this way to make this scenario work?
Add this:
const getItemNestedProperty = (item: Item, nestedProperty: string): string => {
return nestedProperty.split('.').reduce((o, i) => o[i], item)
}
Replace
const itemId = item[conf.id]
const parentId = item[conf.parentId]
with:
const itemId = getItemNestedProperty(item, conf.id)
const parentId = getItemNestedProperty(item, conf.parentId)
Thanks!
Metadata
Metadata
Assignees
Labels
No labels