5 Star 62 Fork 13

阿森 / js.tree

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
toRows.md 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
zhengxs 提交于 2021-07-11 15:48 . Update toRows.md

toRows 树转行

将树结构转成一唯数组

import { toRows } from '@zhengxs/js.tree'

const data = [
  {
    title: '财务',
    children: [
      { title: '收入流失', children: [] },
      { title: '财务设置', children: [] },
    ],
  },
  {
    title: '站点设置',
    children: [
      { title: '收入流失', children: [] },
      { title: '财务设置', children: [] },
    ],
  },
]

toRows(data)
// ->
// [
//   { title: '财务' },
//   { title: '收入流失' },
//   { title: '财务设置' },
//   { title: '站点设置' },
//   { title: '收入流失' },
//   { title: '财务设置' }
// ]

默认子级列表的属性名称是 children,可以通过第三个参数修改

import { toRows } from '@zhengxs/js.tree'

const data = [
  {
    title: '财务',
    items: [
      { title: '收入流失', items: [] },
      { title: '财务设置', items: [] },
    ],
  },
  {
    title: '站点设置',
    items: [
      { title: '收入流失', items: [] },
      { title: '财务设置', items: [] },
    ],
  },
]

// 指定子级列表的属性
toRows(data, 'items')
// ->
// [
//   { title: '财务' },
//   { title: '收入流失' },
//   { title: '财务设置' },
//   { title: '站点设置' },
//   { title: '收入流失' },
//   { title: '财务设置' }
// ]
TypeScript
1
https://gitee.com/zhengxs2018/js.tree.git
git@gitee.com:zhengxs2018/js.tree.git
zhengxs2018
js.tree
js.tree
main

搜索帮助