代码拉取完成,页面将自动刷新
可以使用 filter
函数过滤掉不想要的数据
回调函数参数:
import { filter } from '@zhengxs/js.tree'
const data = [
{
title: '财务',
children: [
{ title: '收入流失', children: [] },
{ title: '财务设置', children: [] },
],
},
{
title: '站点设置',
children: [
{ title: '收入流失', children: [] },
{ title: '财务设置', children: [] },
],
},
]
const result = filter(data, (node, index, parents) => {
return node.title.indexOf('设置') > -1
})
// ->
// [
// {
// title: '财务',
// children: [
// { title: '财务设置' }
// ]
// },
// {
// title: '站点设置',
// children: [
// { title: '收入流失' },
// { title: '财务设置' }
// ]
// }
// ]
默认子级列表的属性名称是 children,可以通过第三个参数修改
import { filter } from '@zhengxs/js.tree'
const data = [
{
title: '财务',
items: [
{ title: '收入流失', items: [] },
{ title: '财务设置', items: [] },
],
},
{
title: '站点设置',
items: [
{ title: '收入流失', items: [] },
{ title: '财务设置', items: [] },
],
},
]
// 如果不是 children 属性,可以通过第三个参数指定,可选
const result = filter(data, ({ title }) => title.indexOf('设置') > -1, 'items')
// ->
// [
// {
// title: '财务',
// items: [
// { title: '财务设置', items: [] }
// ]
// },
// {
// title: '站点设置',
// items: [
// { title: '收入流失' },
// { title: '财务设置' }
// ]
// }
// ]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。