Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gem-mine/array-data-filter

基于 array-tree-filter 修改的数组树过滤器
https://github.com/gem-mine/array-data-filter

Last synced: about 1 month ago
JSON representation

基于 array-tree-filter 修改的数组树过滤器

Awesome Lists containing this project

README

        

# array-data-filter

Filter by keys in tree structure

```
import arrayDataFilter from 'array-data-filter';
const addressOptions = {
noChoice: true,
data: [
{
label: '福建',
value: 'fj',
children: {
noChoice: true,
data: [
{
label: '福州',
value: 'fuzhou',
children: {
noChoice: true,
data: [
{
label: '马尾',
value: 'mawei',
children: { data: [{ label: '马尾镇', value: 'maweizhen' }] },
}
]
}
},
{ label: '泉州', value: 'quanzhou' },
]
}
},
{
label: '北京',
value: 'bj',
children: {
data: [
{
label: '北京',
value: 'beijing',
children: {
noChoice: true,
data: [
{ label: '朝阳区', value: 'chaoyang' },
{ label: '海淀区', value: 'haidian' },
],
},
},
],
},
}
],
}
const values = ['fj', 'fuzhou'];
const result = arrayDataFilter(
addressOptions.data, (item, level) => item.value === values[level]
);

console.log(result);
//[
// {label: "福建", value: "fj", children: {…}},
// {label: "福州", value: "fuzhou", children: {…}}
//]
```