# expanded-tree-tools

> **要求的数组结构如下** ```js const yourArrayData = [ { id: 1, cj: 1, }, { id: 2, cj: 2, }, { id: 3, cj: 3, }, { id: 4, cj: 2, }, { id: 5, cj: 3, }, { id: 6, cj: 4, }, ] ``` **使用 id 判断唯一值，使用 cj 找到父级节点及子节点**

Latest version **1.0.4** (published 2021-05-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install expanded-tree-tools
pnpm add expanded-tree-tools
yarn add expanded-tree-tools
bun add expanded-tree-tools
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-05-10 |
| First published | 2021-01-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | coyle |
| Maintainers | coyle13 |

## Links

- npm: https://www.npmjs.com/package/expanded-tree-tools
- npm.io page: https://npm.io/package/expanded-tree-tools

## Recent versions

- 1.0.4 (latest) — 2021-05-10
- 1.0.3 — 2021-01-07
- 1.0.2 — 2021-01-06
- 1.0.1 — 2021-01-06
- 1.0.0 — 2021-01-06

## README

## 此插件用于拥有cj属性的数组的一些常见操作

**要求的数组结构如下**
```js
const yourArrayData = [
    { id: 1, cj: 1, },
    { id: 2, cj: 2, },
    { id: 3, cj: 3, },
    { id: 4, cj: 2, },
    { id: 5, cj: 3, },
    { id: 6, cj: 4, },
]
```
**使用 id 判断唯一值，使用 cj 找到父级节点及子节点**

## API

#### 1.getParentIndexByRowIndex：根据当前行的index获取当前行的父节点的行index

```js
import { getParentIndexByRowIndex } from 'expanded-tree-tools';
const parentRowIndex = getParentIndexByRowIndex(arrayList, rowIndex);
```

*Params*

* `arrayList` **{Array}**: 数组
* `rowIndex` **{Number}**: 当前行index

#### 2.getRowIndexByIdValue：根据 idValue 获得此id所在行的rowIndex

```js
import { getRowIndexByIdValue } from 'expanded-tree-tools';
const rowIndexById = getRowIndexByIdValue(arrayList, idValue, idLabel);
```

*Params*

* `arrayList` **{Array}**: 数组
* `idValue` **{Number}**: 所需要查找的行的id的值
* `idLabel` **{Number}**: id属性的字段名称，如：'id','jdid'

#### 3.findNextSameLevelRow：根据 rowIndex 找到此行的同一级的下一行的index

```js
import { findNextSameLevelRow } from 'expanded-tree-tools';
const nextSameLevelRowIndex = findNextSameLevelRow(arrayList, rowIndex);
```

*Params*

* `arrayList` **{Array}**: 数组
* `rowIndex` **{Number}**: 当前行index


#### 4.findPreviousSameLevelRow：根据 rowIndex 找到此行的同一级上一行的index

```js
import { findPreviousSameLevelRow } from 'expanded-tree-tools';
const previousSameLevelRowIndex = findPreviousSameLevelRow(arrayList, rowIndex);
```

*Params*

* `arrayList` **{Array}**: 数组
* `rowIndex` **{Number}**: 当前行index

#### 5.isLastNodeInParent：根据 rowIndex 判断 当前节点是不是其父节点的最后一个子节点

```js
import { isLastNodeInParent } from 'expanded-tree-tools';
const isLastNode = isLastNodeInParent(arrayList, rowIndex);
```

*Params*

* `arrayList` **{Array}**: 数组
* `rowIndex` **{Number}**: 当前行index

#### 6.getChildArrayInParent：获取 此节点下所有的直接子节点

***返回值结构为 { n: XX, obj: XX } n表示rowIndex, obj表示当前行的数据***

```js
import { getChildArrayInParent } from 'expanded-tree-tools';
const childArray = getChildArrayInParent(arrayList, rowIndex);
```

*Params*

* `arrayList` **{Array}**: 数组
* `rowIndex` **{Number}**: 当前行index

#### 7.getIndexInParentByRowIndex：根据 当前节点的 rowIndex 获得 其在其直接父节点 中的 索引位置

```js
import { getIndexInParentByRowIndex } from 'expanded-tree-tools';
const indexInParent = getIndexInParentByRowIndex(arrayList, rowIndex);
```

*Params*

* `arrayList` **{Array}**: 数组
* `rowIndex` **{Number}**: 当前行index

#### 8.isFirstNodeInParent：根据 rowIndex 判断 当前节点是不是其父节点的第一个子节点

```js
import { isFirstNodeInParent } from 'expanded-tree-tools';
const isFirstNode = isFirstNodeInParent(arrayList, rowIndex);
```

*Params*

* `arrayList` **{Array}**: 数组
* `rowIndex` **{Number}**: 当前行index


#### 9.getLastChildNodeIndexByParentIndex：根据父节点的 rowIndex 获取 此父节点最后一个子孙节点的位置

```js
import { getLastChildNodeIndexByParentIndex } from 'expanded-tree-tools';
const lastChildNodeIndex = getLastChildNodeIndexByParentIndex(arrayList, rowIndex);
```

*Params*

* `arrayList` **{Array}**: 数组
* `rowIndex` **{Number}**: 当前行index

## About

### Author

**coyle**

* [github/skyroom](https://github.com/skyroom)

### License

Released under the [MIT license].

***

---
_Source: https://npm.io/package/expanded-tree-tools · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
