1.0.4 • Published 3 years ago

expanded-tree-tools v1.0.4

Weekly downloads
5
License
MIT
Repository
-
Last release
3 years ago

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

要求的数组结构如下

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

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

Params

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

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

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

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

Params

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

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

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

Params

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

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

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表示当前行的数据

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

Params

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

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

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

Params

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

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

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

Params

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

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

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

Params

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

About

Author

coyle

License

Released under the MIT license.


1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago