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

Question - load tree #6

Closed
rodgomesc opened this issue Apr 24, 2020 · 3 comments
Closed

Question - load tree #6

rodgomesc opened this issue Apr 24, 2020 · 3 comments

Comments

@rodgomesc
Copy link

rodgomesc commented Apr 24, 2020

any docs about how to load tree with a javascript object instead of using system patchs ?

like:

const data = {
  id: 'root',
  name: 'Parent',
  children: [
    {
      id: '1',
      name: 'Child - 1',
    },
    {
      id: '3',
      name: 'Child - 3',
      children: [
        {
          id: '4',
          name: 'Child - 4',
        },
      ],
    },
  ],
};
@zikaari
Copy link
Owner

zikaari commented Apr 25, 2020

If you don't need renaming and file creation capabilities, you can create a basic "filesystem" adapter. TreeModel requires a host with function getItems which will be called initially for the root path, and then later as the user expands directories. The path will be formatted depending on what you specify for pathStyle i.e win32 or unix, latter recommended.

Then you need to rig your getItems callback to translate requested path to actual location of entity in your "object". Probably by traversing recursively and drilling down by each "path segment" until you hit the thing. You can use splitPath from path-fx library to split a path like "/root/Child - 3/Child - 4" to an array of keys like ["root", "Child - 3", "Child - 4"].

Then just walk the keys recursively.


See also:

https://github.com/NeekSandhu/react-aspen-demo/blob/master/demo/index.tsx#L25-L38

https://github.com/NeekSandhu/react-aspen-demo/blob/master/demo/index.tsx#L40

https://github.com/NeekSandhu/react-aspen-demo/blob/master/demo/index.tsx#L70


Basically you should just fork the react-aspen-demo repo to get a boost

@zikaari
Copy link
Owner

zikaari commented May 10, 2020

Did this solve your problem?

@zikaari
Copy link
Owner

zikaari commented Sep 22, 2021

Closing due to inactivity

@zikaari zikaari closed this as completed Sep 22, 2021
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