Skip to content

Enable nested id and parentId properties #20

@gregoryforel

Description

@gregoryforel

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions