ltt
list-to-tree-lite-sinnbo
npm i list-to-tree-lite-sinnbo
ltt

list-to-tree-lite-sinnbo

A simple function converts a list of flat-objects to a list of tree-objects

by William Leung

0.1.5 (see all)License:MITTypeScript:Not Found
npm i list-to-tree-lite-sinnbo
Readme

Build Status

An alternative of list-to-tree-lite by sinnbo.com.

list-to-tree-lite

A simple function converts a flat-list of objects with id, parent and children to a tree-list of objects.
without any dependencies.

[{
    id: 6,
    any: 'opps'
}, {
    id: 2,
    parent: 5,
    any: 'foo',
}, {
    id: 1,
    parent: 2,
    any: 'bar'
}, {
    id: 5,
    any: 'hello'
}, {
    id: 3,
    parent: 2,
    any: 'other'
}]

to

[{
    id: 6,
    any: 'opps',
    children: []
}, {
    id: 5,
    any: 'hello',
    children: [{
        id: 2,
        parent: 5,
        any: 'foo',
        children: [{
            id: 1,
            parent: 2,
            any: 'bar',
            children: []
        }, {
            id: 3,
            parent: 2,
            any: 'other',
            children: []
        }]
    }]
}]

#Usage
listToTree(list[, options])

options.idKey
the id key of the item object, default id

options.parentKey
the parent key of the item object, default parent

options.childrenKey
the children key of the item object, default children

options.mustChild
用于控制子节点为空数组时,节点本身是否显示children属性,为true时显示空数组,反之不显示

#Install npm install list-to-tree-lite-sinnbo --save

#Test
npm run test

#License
MIT:http://william17.mit-license.org

Downloads/wk

1

GitHub Stars

52

LAST COMMIT

7yrs ago

MAINTAINERS

1

CONTRIBUTORS

1

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
0.1.5
latest
5yrs ago
No alternatives found
No tutorials found
Add a tutorial

Rate & Review

100
No reviews found
Be the first to rate