Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 修改的数组树过滤器
- Host: GitHub
- URL: https://github.com/gem-mine/array-data-filter
- Owner: gem-mine
- Created: 2020-07-31T11:08:03.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T20:38:29.000Z (about 2 years ago)
- Last Synced: 2024-04-13T19:06:03.741Z (9 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.85 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: readme.md
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: {…}}
//]
```