Skip to content

dirkarnez/tree.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree.js

Build tree from list using id key and parent key. Default id key value is _id, parent key - _parent

Install

Install with npm

npm install list-to-tree2

Install with yarn

yarn add list-to-tree2

Tests

npm test

Usage

Also you can open example.js to see usage

const listToTree = require('list-to-tree2');
const list = [{
			_id: 1,
			_parent: null,
			prop: 'qwerty',
		}, {
			_id: 2,
			_parent: 1,
			prop: 'asdfg',
		}, {
			_id: 3,
			_parent: null,
			prop: '13sdf',
		}];
    
const tree = listToTree(list);

Parameters

  • list - Array of objects with Id key and parentId key. Required
  • idKey - Name of id key in list elements. Default - _id
  • parentKey - Name of parentId key. Default - _parent

About

Converting list to tree structure

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%