1.0.1 • Published 3 years ago

@jswork/next-tree v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

next-tree

Tree data for next.

version license size download

installation

npm install -S @jswork/next-tree

apis

apiparamsdescription
childrencallbackFind children only on level
parentcallbackFind parent only one level
descendantscallbackFind descendants recursion
ancestorscallbackFind ancestors recursion
findcallback-
filtercallback-
searchcallback-
tablecallbackCreate table data

usage

import NxTree from '@jswork/next-tree';

const treeData = {
  label: '空间',
  value: '/admin/space',
  children: [
    {
      label: '空间-子级1',
      value: '/admin/space/:id',
      children: [
        {
          label: '空间导出',
          value: '/admin/space/:id/export'
        }
      ]
    },
    {
      label: '空间-子级2',
      value: '/admin/space2/:id',
      children: [
        {
          label: '空间导出222',
          value: '/admin/space/:id/expor2222t'
        }
      ]
    }
  ]
};

const item = NxTree.create(treeData).find((_, item) => item.label === '空间导出222');
const data = NxTree.serialize(item);

// results:
{
  label: '空间导出222',
  value: '/admin/space/:id/expor2222t',
  depth: 2,
  independent: true
}

license

Code released under the MIT license.