react-component / react-component/tree

Custom key name for the children of a tree

Open
#384 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.3k
Forks
490
Avg merge
3d 17h
Merged PRs (30d)
5

Description

Greetings.

The component expects the prop "treeData" to look like this:
const treeData = [ { title: 'parent 1', key: '0-0', children: [ { title: 'parent 1-0', key: '0-0-0', disabled: true, children: [ { title: 'leaf', key: '0-0-0-0', disableCheckbox: true, }, { title: 'leaf', key: '0-0-0-1', }, ], }, { title: 'parent 1-1', key: '0-0-1', children: [{ title: <span style={{ color: '#1890ff' }}>sss</span>, key: '0-0-1-0' }], }, ], }, ];

The problem is, my data structure uses a different key to specify the children. In other words, I have a key called "descendants" instead of "children", and the structure looks more like this (with the change bolded)
const treeData = [ { title: 'parent 1', key: '0-0', **descendants**: [ { title: 'parent 1-0', key: '0-0-0', disabled: true, **descendants**: [ { title: 'leaf', key: '0-0-0-0', disableCheckbox: true, }, { title: 'leaf', key: '0-0-0-1', }, ], }, { title: 'parent 1-1', key: '0-0-1', **descendants**: [{ title: <span style={{ color: '#1890ff' }}>sss</span>, key: '0-0-1-0' }], }, ], }, ];

Is is possible to specify a custom key name instead of "children"? For instance,

Thanks

Sorry the formatting doesn't seem to work well

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the component and trace where it reads the fixed children key. Verify how a childrenKey="descendants" option should affect nested data while preserving the default behavior; the issue is done when descendants render correctly as tree children.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.